Skip to content

Commit

Permalink
Merge PR #3936 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by aleuffre
  • Loading branch information
OCA-git-bot committed Feb 16, 2024
2 parents 0301628 + f2e04bc commit 4579ff2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions l10n_it_delivery_note/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions l10n_it_delivery_note/security/res_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<field name="category_id" ref="base.module_category_hidden" />
</record>

<record id="group_required_partner_ref" model="res.groups">
<field name="name">Make Partner Ref. in DN Required</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>

<record id="can_change_number" model="res.groups">
<field name="name">Allow to change delivery note number</field>
<field
Expand Down
36 changes: 36 additions & 0 deletions l10n_it_delivery_note/tests/test_stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,39 @@ def test_delivery_action_confirm(self):
"different from the shipping method set in picking(s)",
warning_context.get("default_warning_message"),
)

def test_delivery_action_confirm_without_ref(self):
user = new_test_user(
self.env,
login="test",
groups="stock.group_stock_manager,"
"l10n_it_delivery_note.use_advanced_delivery_notes,"
"l10n_it_delivery_note.group_required_partner_ref",
)
# change user in order to activate DN advanced settings
self.env.user = user

picking = self.create_picking(
picking_type_id=self.env.ref("stock.picking_type_in").id,
carrier_id=self.env.ref("delivery.delivery_carrier").id,
)
picking.move_lines.quantity_done = 1
picking.button_validate()

dn_form = Form(
self.env["stock.delivery.note.create.wizard"].with_context(
{"active_id": picking.id, "active_ids": picking.ids}
)
)
dn = dn_form.save()
dn.confirm()

delivery_note_id = picking.delivery_note_id

with self.assertRaises(UserError) as exc:
delivery_note_id.action_confirm()
exc_message = exc.exception.args[0]
self.assertIn("The field 'Partner reference' is mandatory", exc_message)

delivery_note_id.partner_ref = "Reference #1234"
delivery_note_id.action_confirm()
14 changes: 14 additions & 0 deletions l10n_it_delivery_note/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="group_required_partner_ref" />
</div>
<div class="o_setting_right_pane">
<label for="group_required_partner_ref" />
<div class="text-muted">
<p>
Block the validation of incoming DNs if the
"Partner reference" field is not set.
</p>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label for="virtual_locations_root" />
Expand Down

0 comments on commit 4579ff2

Please sign in to comment.