Skip to Content
Menu
This question has been flagged

Hi everyone. I have a custom module which add and update supplier price and code, from PO line.

I have add a boolean field in PO line.

I would like not update supplier price, if boolean field is True.

Can anyone help me? I'm not a developer, and I don't know how do it.

Below code with part interested Bold

Thanks

class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'

    product_supplier_code = fields.Char(string='Product Supplier Code')
    not_update = fields.Boolean(string='Not update price')

    @api.onchange(
        'partner_id',
        'product_id',
    )
    def _onchange_product_code(self):
        for line in self:
            supplier_info = line.product_id.seller_ids.filtered(
                lambda s: (
                    s.product_id == line.product_id
                    and s.name == line.partner_id
                )
            )
            if supplier_info:
                code = supplier_info[0].product_code or ''
                line.product_supplier_code = code
            else:
                supplier_info = line.product_id.seller_ids.filtered(
                    lambda s: (
                        s.product_tmpl_id == line.product_id.product_tmpl_id
                        and s.name == line.partner_id
                    )
                )
                if supplier_info:
                    code = supplier_info[0].product_code or ''
                    line.product_supplier_code = code


class PurchaseOrder(models.Model):
    _inherit = 'purchase.order'

    def _add_supplier_to_product(self):
        super()._add_supplier_to_product()
        for line in self.order_line:
            partner = (
                self.partner_id
                if not self.partner_id.parent_id
                else self.partner_id.parent_id
            )
            if partner in line.product_id.seller_ids.mapped('name'):
                seller = line.product_id._select_seller(
                    partner_id=line.partner_id,
                    quantity=line.product_qty,
                    date=line.order_id.date_order
                    and line.order_id.date_order.date(),
                    uom_id=line.product_uom,
                )
                if seller:
                    try:
                        seller['product_code'] = line.product_supplier_code
                        seller['price'] = line.price_unit
                    except AccessError:
                        break
Avatar
Discard
Related Posts Replies Views Activity
4
Aug 23
13614
3
May 19
12534
3
Dec 24
2385
1
Jul 24
712
1
Jun 24
785