[IMP] sale_stock: Compute the related sales orders on production lots
Add a computed field on a stock.production.lot to retrieve all the sales orders coming from a done stock.move.line if the stock.move is also done and if the destination usage is 'customer'.
This commit is contained in:
committed by
Yannick Tivisse
parent
946189eeff
commit
cfd3e6b369
@@ -36,6 +36,7 @@ You can choose flexible invoicing methods:
|
||||
'views/sale_stock_portal_template.xml',
|
||||
'views/product_template_views.xml',
|
||||
'views/res_users_views.xml',
|
||||
'views/stock_production_lot_views.xml',
|
||||
'report/sale_order_report_templates.xml',
|
||||
'report/stock_report_deliveryslip.xml',
|
||||
'data/sale_stock_data.xml',
|
||||
|
||||
@@ -101,3 +101,18 @@ class StockPicking(models.Model):
|
||||
self._log_activity(_render_note_exception_quantity, documents)
|
||||
|
||||
return super(StockPicking, self)._log_less_quantities_than_expected(moves)
|
||||
|
||||
class ProductionLot(models.Model):
|
||||
_inherit = 'stock.production.lot'
|
||||
|
||||
sale_order_ids = fields.Many2many('sale.order', string="Sales Orders", compute='_compute_sale_order_ids')
|
||||
|
||||
@api.depends('name')
|
||||
def _compute_sale_order_ids(self):
|
||||
for lot in self:
|
||||
stock_moves = self.env['stock.move.line'].search([
|
||||
('lot_id', '=', lot.id),
|
||||
('state', '=', 'done')
|
||||
]).mapped('move_id').filtered(
|
||||
lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done')
|
||||
lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id')
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="stock_production_lot_view_form" model="ir.ui.view">
|
||||
<field name="name">stock.production.lot.view.form</field>
|
||||
<field name="model">stock.production.lot</field>
|
||||
<field name="inherit_id" ref="stock.view_production_lot_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='main_group']" position="after">
|
||||
<group>
|
||||
<field name="sale_order_ids" widget="many2many" readonly="True">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="confirmation_date"/>
|
||||
<field name="state" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="stock_production_lot_view_form_simple" model="ir.ui.view">
|
||||
<field name="name">stock.production.lot.view.form.simple</field>
|
||||
<field name="model">stock.production.lot</field>
|
||||
<field name="inherit_id" ref="stock.view_production_lot_form_simple"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='main_group']" position="after">
|
||||
<group>
|
||||
<field name="sale_order_ids" widget="many2many" readonly="True">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="confirmation_date"/>
|
||||
<field name="state" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user