Skip to content

Commit

Permalink
[FIX] l10n_it_delivery_note: carrier syncing
Browse files Browse the repository at this point in the history
- Set the delivery note carrier as a 'delivery carrier' instead of a
  partner
- Sync the carrier between the picking and the delivery note
- All the pickings carriers inside a DN must be the same
  • Loading branch information
renda-dev committed Jan 5, 2024
1 parent 05f247b commit 73b95db
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def vals_getter(record):
"partner_shipping_id": record.partner_shipping_id.id,
"type_id": self._document_types[record.ddt_type_id].id,
"date": record.date,
"carrier_id": record.carrier_id.id,
"carrier_id": record.picking_ids[:1].carrier_id.id,
"delivery_method_id": record.partner_id.property_delivery_carrier_id.id,
"transport_datetime": record.date_done,
"packages": record.parcels,
Expand Down
9 changes: 9 additions & 0 deletions l10n_it_delivery_note/mixins/picking_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def _check_pickings_partners(self, pickings):
_("You need to select pickings with all the same recipient.")
)

@api.model
def _check_pickings_carriers(self, pickings):
carrier_ids = pickings.mapped("carrier_id")
if len(carrier_ids) > 1:
raise ValidationError(
_("You need to select pickings with all the same carriers.")
)

@api.model
def _check_pickings_src_locations(self, pickings):
src_locations = pickings.mapped("location_id")
Expand Down Expand Up @@ -130,5 +138,6 @@ def check_compliance(self, pickings):
self._check_pickings_state(pickings)
self._check_pickings_types(pickings)
self._check_pickings_partners(pickings)
self._check_pickings_carriers(pickings)
self._check_pickings_src_locations(pickings)
self._check_pickings_dest_locations(pickings)
2 changes: 1 addition & 1 deletion l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _domain_weight_uom(self):
)

carrier_id = fields.Many2one(
"res.partner",
"delivery.carrier",
string="Carrier",
states=DONE_READONLY_STATE,
tracking=True,
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_delivery_note/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StockPicking(models.Model):
)

delivery_note_carrier_id = fields.Many2one(
"res.partner", string="DN Carrier", related="delivery_note_id.carrier_id"
"delivery.carrier", string="DN Carrier", related="delivery_note_id.carrier_id"
)
delivery_method_id = fields.Many2one(
"delivery.carrier", related="delivery_note_id.delivery_method_id"
Expand Down Expand Up @@ -346,6 +346,7 @@ def _create_delivery_note(self):
"partner_shipping_id": partners[1].id,
"type_id": type_id.id,
"date": self.date_done,
"carrier_id": self.carrier_id.id,
"delivery_method_id": self.partner_id.property_delivery_carrier_id.id,
"transport_condition_id": (
self.sale_id.default_transport_condition_id.id
Expand Down
1 change: 1 addition & 0 deletions l10n_it_delivery_note/wizard/delivery_note_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _get_validation_errors(self, pickings):
(self._check_pickings_state, False),
(self._check_pickings_types, False),
(self._check_pickings_partners, False),
(self._check_pickings_carriers, False),
(self._check_pickings_src_locations, False),
(self._check_pickings_dest_locations, False),
(self._check_delivery_notes, False),
Expand Down
1 change: 1 addition & 0 deletions l10n_it_delivery_note/wizard/delivery_note_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def confirm(self):
"partner_shipping_id": self.partner_shipping_id.id,
"type_id": self.type_id.id,
"date": self.date,
"carrier_id": self.selected_picking_ids.carrier_id.id,
"delivery_method_id": self.partner_id.property_delivery_carrier_id.id,
"transport_condition_id": sale_order_id
and sale_order_id.default_transport_condition_id.id
Expand Down

0 comments on commit 73b95db

Please sign in to comment.