Skip to content

Commit

Permalink
[IMP] stock_outgoing_shipment_report: use fields from picking instead…
Browse files Browse the repository at this point in the history
… of sale order
  • Loading branch information
AungKoKoLin1997 committed Feb 9, 2024
1 parent 79beb6a commit 23df894
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions stock_outgoing_shipment_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"views/res_partner_views.xml",
"views/sale_order_views.xml",
"views/stock_outgoing_shipment_report_views.xml",
"views/stock_picking_views.xml",
],
}
12 changes: 12 additions & 0 deletions stock_outgoing_shipment_report/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def _onchange_carrier_id(self):
else:
self.shipping_use_carrier_acct = False

@api.multi
def action_confirm(self):
res = super(SaleOrder, self).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,
})
return res

@api.multi
def write(self, vals):
res = super(SaleOrder, self).write(vals)
Expand Down
21 changes: 12 additions & 9 deletions stock_outgoing_shipment_report/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

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 generate_stock_outgoing_shipment_report(self):
moves = self.mapped("move_lines")
self._cr.execute("DELETE FROM stock_outgoing_shipment_report")
for move in moves:
order = move.sale_line_id.order_id if move.sale_line_id else False
picking = move.picking_id
partner = move.picking_partner_id
product = move.product_id
vals = {"move_id": move.id}
if order:
carrier = order.carrier_id
vals["carrier_id"] = carrier.id if carrier else False
vals["ship_service_id"] = (
order.delivery_carrier_service_id
and order.delivery_carrier_service_id.id
)
vals["ship_account"] = order.shipping_use_carrier_acct
carrier = picking.carrier_id
vals["carrier_id"] = carrier.id if carrier else False
vals["ship_service_id"] = (
picking.delivery_carrier_service_id
and picking.delivery_carrier_service_id.id
)
vals["ship_account"] = picking.shipping_use_carrier_acct
vals["ship_date_edit"] = fields.Datetime.context_timestamp(
self, picking.scheduled_date
).date()
Expand Down
14 changes: 14 additions & 0 deletions stock_outgoing_shipment_report/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_picking_form_inherit" model="ir.ui.view">
<field name="name">stock.picking.form.inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='carrier_id']" position="after">
<field name="delivery_carrier_service_id"/>
<field name="shipping_use_carrier_acct"/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 23df894

Please sign in to comment.