-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23df894
commit 5aefb2f
Showing
7 changed files
with
99 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
stock_outgoing_shipment_report/models/carrier_info_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class CarrierInfoMixin(models.AbstractModel): | ||
"""This model should only be inherited by a model with `carrier_id` field.""" | ||
_name = "carrier.info.mixin" | ||
_description = "Carrier Information Mixin" | ||
|
||
shipping_insurance_amt = fields.Float( | ||
"Shipping Insurance Amount", help="For information only." | ||
) | ||
delivery_carrier_service_id = fields.Many2one( | ||
"delivery.carrier.service", | ||
string="Delivery Service", | ||
domain="[('carrier_id', '=', carrier_id)]", | ||
) | ||
shipping_use_carrier_acct = fields.Char("Delivery Carrier Account Number") | ||
|
||
@api.multi | ||
def _get_partner_shipping(self): | ||
raise NotImplementedError | ||
|
||
@api.onchange("carrier_id") | ||
def _onchange_carrier_id(self): | ||
self.delivery_carrier_service_id = False | ||
partner = self._get_partner_shipping() | ||
account_ids = partner.delivery_carrier_account_ids | ||
carrier_acct = account_ids.filtered( | ||
lambda l: l.carrier_id == self.carrier_id | ||
)[:1] | ||
if carrier_acct: | ||
self.shipping_use_carrier_acct = carrier_acct.delivery_carrier_account_num | ||
else: | ||
self.shipping_use_carrier_acct = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,54 @@ | ||
# Copyright 2019 Quartile Limited | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
# Copyright 2019-2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo import api, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
_name = "sale.order" | ||
_inherit = ["sale.order", "carrier.info.mixin"] | ||
|
||
shipping_insurance_amt = fields.Float( | ||
"Shipping Insurance Amount", help="For information only." | ||
) | ||
delivery_carrier_service_id = fields.Many2one( | ||
"delivery.carrier.service", string="Delivery Service", | ||
) | ||
shipping_use_carrier_acct = fields.Char(string="Delivery Carrier Account Number",) | ||
@api.multi | ||
def _get_partner_shipping(self): | ||
self.ensure_one() | ||
return self.partner_shipping_id | ||
|
||
@api.onchange("carrier_id") | ||
def _onchange_carrier_id(self): | ||
account_ids = self.partner_shipping_id.delivery_carrier_account_ids | ||
if self.carrier_id and account_ids.filtered( | ||
lambda l: l.carrier_id == self.carrier_id | ||
): | ||
self.shipping_use_carrier_acct = account_ids.filtered( | ||
lambda l: l.carrier_id == self.carrier_id | ||
).delivery_carrier_account_num | ||
else: | ||
self.shipping_use_carrier_acct = False | ||
@api.onchange("partner_shipping_id") | ||
def _onchange_partner_shipping_id(self): | ||
self._onchange_carrier_id() | ||
return super()._onchange_partner_shipping_id() | ||
|
||
@api.multi | ||
def action_confirm(self): | ||
res = super(SaleOrder, self).action_confirm() | ||
res = super().action_confirm() | ||
for order in self: | ||
for pick in order.picking_ids: | ||
pick.write({ | ||
'carrier_id': order.carrier_id.id, | ||
'delivery_carrier_service_id': order.delivery_carrier_service_id.id, | ||
'shipping_use_carrier_acct': order.shipping_use_carrier_acct, | ||
}) | ||
order.picking_ids.write( | ||
{ | ||
"carrier_id": order.carrier_id.id, | ||
"delivery_carrier_service_id": order.delivery_carrier_service_id.id, | ||
"shipping_use_carrier_acct": order.shipping_use_carrier_acct, | ||
} | ||
) | ||
return res | ||
|
||
@api.multi | ||
def write(self, vals): | ||
res = super(SaleOrder, self).write(vals) | ||
if "carrier_id" in vals: | ||
for order in self: | ||
pickings = order.mapped("picking_ids").filtered( | ||
lambda p: p.state not in ("done", "cancel") | ||
) | ||
pickings.update({"carrier_id": vals["carrier_id"]}) | ||
res = super().write(vals) | ||
if not any( | ||
key in vals for key in [ | ||
"carrier_id", "delivery_carrier_service_id", "shipping_use_carrier_acct" | ||
] | ||
): | ||
return res | ||
for order in self: | ||
pickings = order.mapped("picking_ids").filtered( | ||
lambda p: p.state not in ("done", "cancel") | ||
) | ||
pickings.write( | ||
{ | ||
"carrier_id": order.carrier_id.id, | ||
"delivery_carrier_service_id": order.delivery_carrier_service_id.id, | ||
"shipping_use_carrier_acct": order.shipping_use_carrier_acct, | ||
} | ||
) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters