如何在交货单的所有步骤中添加 sale_line_id 字段?

问题描述 投票:0回答:1

Odoo 14 社区版

据我了解,

sale_line_id
模型中的
stock.move
仅在交货订单上创建时添加。假设我有 3 个步骤:
pick
pack
out
。只有
out
具有
sale_line_id
中的值。我想进行自定义,以便所有步骤都包含
sale_line_id
值。

所以,我想知道我必须在哪个模型中进行调整才能使其包含用于其他步骤的

sale_line_id
字段。

我尝试追踪流程,但我不太熟悉。

我研究过这些方法,但找不到正确的方法。

_action_launch_stock_rule
_run_pull
_get_stock_move_values
_get_custom_move_fields

更新

我刚刚发现从销售订单行调用

_action_launch_stock_rule
方法来创建具有
sale_line_id
的采购。但是,我仍然找不到创建没有
sale_line_id
字段的其他步骤的位置。

odoo odoo-14
1个回答
0
投票

这里更新

stock_move
记录来设置
sale_line_id
的过程:

在插件/mrp/models/stock_move.py中

class StockMove(models.Model):
    _inherit = 'stock.move'
...
    def write(self, vals):
        if self.env.context.get('force_manual_consumption'):
            vals['manual_consumption'] = True
        if 'product_uom_qty' in vals:
            if 'move_line_ids' in vals:
                # first update lines then product_uom_qty as the later will unreserve
                # so possibly unlink lines
                move_line_vals = vals.pop('move_line_ids')
                super().write({'move_line_ids': move_line_vals})
            procurement_requests = []
            for move in self:
                if move.raw_material_production_id.state != 'confirmed' \
                        or not float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding) \
                        or move.procure_method != 'make_to_order':
                    continue
                values = move._prepare_procurement_values()
                origin = move._prepare_procurement_origin()
                procurement_requests.append(self.env['procurement.group'].Procurement(
                    move.product_id, vals['product_uom_qty'], move.product_uom,
                    move.location_id, move.rule_id and move.rule_id.name or "/",
                    origin, move.company_id, values))
            self.env['procurement.group'].run(procurement_requests)
        return super().write(vals)

在插件/sale_stock/models/sale_order_line.py

        def _prepare_procurement_values(self, group_id=False):
        """ Prepare specific key for moves or other components that will be created from a stock rule
        coming from a sale order line. This method could be override in order to add other custom key that could
        be used in move/po creation.
        """
        values = super(SaleOrderLine, self)._prepare_procurement_values(group_id)
        self.ensure_one()
        # Use the delivery date if there is else use date_order and lead time
        date_deadline = self.order_id.commitment_date or (self.order_id.date_order + timedelta(days=self.customer_lead or 0.0))
        date_planned = date_deadline - timedelta(days=self.order_id.company_id.security_lead)
        values.update({
            'group_id': group_id,
            'sale_line_id': self.id,
            'date_planned': date_planned,
            'date_deadline': date_deadline,
            'route_ids': self.route_id,
            'warehouse_id': self.order_id.warehouse_id or False,
            'partner_id': self.order_id.partner_shipping_id.id,
            'product_description_variants': self.with_context(lang=self.order_id.partner_id.lang)._get_sale_order_line_multiline_description_variants(),
            'company_id': self.order_id.company_id,
            'product_packaging_id': self.product_packaging_id,
            'sequence': self.sequence,
        })
        return values
© www.soinside.com 2019 - 2024. All rights reserved.