[ENH] delivery_carrier_partner_account: add delivery info to sale line
When adding transport charges to a sale order via the "Add Shipping" button, the line's description now contains the delivery billing mode and account number when applicable. Fixes #112
This commit is contained in:
parent
15aee61953
commit
a365609f21
3 changed files with 61 additions and 1 deletions
|
|
@ -28,3 +28,15 @@ class SalesOrder(models.Model):
|
||||||
):
|
):
|
||||||
picking.carrier_account_id = rec.carrier_account_id
|
picking.carrier_account_id = rec.carrier_account_id
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _create_delivery_line(self, carrier, price_unit):
|
||||||
|
line = super()._create_delivery_line(carrier, price_unit)
|
||||||
|
name = line.name
|
||||||
|
delivery_billing_mode = self.env.context.get("delivery_billing_mode", False)
|
||||||
|
carrier_account = self.env.context.get("carrier_account", False)
|
||||||
|
if delivery_billing_mode:
|
||||||
|
name = name + f" [{delivery_billing_mode.upper()}]"
|
||||||
|
if delivery_billing_mode in ["collect", "third party"] and carrier_account:
|
||||||
|
name = name + f" #{carrier_account.account_number}"
|
||||||
|
line.name = name
|
||||||
|
return line
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,45 @@ class TestSalesOrder(TestCarrierAccountCommon):
|
||||||
self.client_partner.property_delivery_carrier_id = self.delivery_carrier_1
|
self.client_partner.property_delivery_carrier_id = self.delivery_carrier_1
|
||||||
self.client_partner.default_carrier_account_id = self.client_account_1
|
self.client_partner.default_carrier_account_id = self.client_account_1
|
||||||
self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
||||||
|
|
||||||
|
def test_collect_sale_order_line_gets_proper_name(self):
|
||||||
|
order = self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
||||||
|
wiz = self._get_shipping_wizard(order)
|
||||||
|
wiz.carrier_id = self.delivery_carrier_1
|
||||||
|
wiz.delivery_billing_mode = "collect"
|
||||||
|
wiz.button_confirm()
|
||||||
|
self.assertEqual(
|
||||||
|
order.order_line[0].name,
|
||||||
|
f"{self.delivery_carrier_1.name} [COLLECT] #{self.client_account_1.account_number}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_prepaid_sale_order_line_gets_proper_name(self):
|
||||||
|
order = self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
||||||
|
wiz = self._get_shipping_wizard(order)
|
||||||
|
wiz.carrier_id = self.delivery_carrier_1
|
||||||
|
wiz.delivery_billing_mode = "prepaid"
|
||||||
|
wiz.button_confirm()
|
||||||
|
self.assertEqual(
|
||||||
|
order.order_line[0].name,
|
||||||
|
f"{self.delivery_carrier_1.name} [PREPAID]",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_third_party_sale_order_line_gets_proper_name(self):
|
||||||
|
order = self.env["sale.order"].create({"partner_id": self.client_partner.id})
|
||||||
|
wiz = self._get_shipping_wizard(order)
|
||||||
|
wiz.carrier_id = self.delivery_carrier_1
|
||||||
|
wiz.delivery_billing_mode = "third party"
|
||||||
|
wiz.carrier_account_id = self.third_party_account_1
|
||||||
|
wiz.button_confirm()
|
||||||
|
self.assertEqual(
|
||||||
|
order.order_line[0].name,
|
||||||
|
f"{self.delivery_carrier_1.name} [THIRD PARTY] #{self.third_party_account_1.account_number}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_shipping_wizard(self, order):
|
||||||
|
wizard_action = order.action_open_delivery_wizard()
|
||||||
|
return (
|
||||||
|
self.env[wizard_action["res_model"]]
|
||||||
|
.with_context(wizard_action["context"])
|
||||||
|
.create({})
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,13 @@ class ChooseDeliveryCarrier(models.TransientModel):
|
||||||
recipient_id = fields.Many2one(related="partner_id")
|
recipient_id = fields.Many2one(related="partner_id")
|
||||||
|
|
||||||
def button_confirm(self):
|
def button_confirm(self):
|
||||||
res = super().button_confirm()
|
res = super(
|
||||||
|
ChooseDeliveryCarrier,
|
||||||
|
self.with_context(
|
||||||
|
delivery_billing_mode=self.delivery_billing_mode,
|
||||||
|
carrier_account=self.carrier_account_id,
|
||||||
|
),
|
||||||
|
).button_confirm()
|
||||||
extra_vals = {}
|
extra_vals = {}
|
||||||
if self.delivery_billing_mode:
|
if self.delivery_billing_mode:
|
||||||
extra_vals.update(delivery_billing_mode=self.delivery_billing_mode)
|
extra_vals.update(delivery_billing_mode=self.delivery_billing_mode)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue