diff --git a/l10n_it_delivery_note/models/res_config_settings.py b/l10n_it_delivery_note/models/res_config_settings.py index c9090e780f99..7e953ba0d368 100644 --- a/l10n_it_delivery_note/models/res_config_settings.py +++ b/l10n_it_delivery_note/models/res_config_settings.py @@ -17,6 +17,11 @@ def _default_virtual_locations_root(self): implied_group="l10n_it_delivery_note.use_advanced_delivery_notes", ) + group_required_partner_ref = fields.Boolean( + string="Make Partner Ref. in DN Mandatory", + implied_group="l10n_it_delivery_note.group_required_partner_ref", + ) + virtual_locations_root = fields.Many2one( "stock.location", string="Virtual locations root", diff --git a/l10n_it_delivery_note/models/stock_delivery_note.py b/l10n_it_delivery_note/models/stock_delivery_note.py index 1659618de3b8..c8a2671ebc7c 100644 --- a/l10n_it_delivery_note/models/stock_delivery_note.py +++ b/l10n_it_delivery_note/models/stock_delivery_note.py @@ -551,6 +551,20 @@ def _action_confirm(self): def action_confirm(self): for note in self: + if ( + note.type_code == "incoming" + and not note.partner_ref + and self.env.user.has_group( + "l10n_it_delivery_note.group_required_partner_ref" + ) + ): + raise UserError( + _( + "The field 'Partner reference' is " + "mandatory to validate the Delivery Note." + ) + ) + warning_message = False carrier_ids = note.mapped("picking_ids.carrier_id") carrier_partner_ids = carrier_ids.mapped("partner_id") diff --git a/l10n_it_delivery_note/security/res_groups.xml b/l10n_it_delivery_note/security/res_groups.xml index bab6cedc0322..4e13eabd9067 100644 --- a/l10n_it_delivery_note/security/res_groups.xml +++ b/l10n_it_delivery_note/security/res_groups.xml @@ -10,6 +10,11 @@ + + Make Partner Ref. in DN Required + + + Allow to change delivery note number + + + + + + + + + Block the validation of incoming DNs if the + "Partner reference" field is not set. + + + +
+ Block the validation of incoming DNs if the + "Partner reference" field is not set. +