Contributors mailing list archives

Browse archives


Re: How to propagate custom info/note from Sale Order Line to Purchase Order Line using MTO

Iván Todorovich
- 13/11/2020 16:00:31
Hi Radovan,

We've done something similar like this:

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

    def _merge_in_existing_line(
            self, product_id, product_qty, product_uom,
            location_id, name, origin, values):
        """ Avoid merging lines if they have different names """
        line_name = ', '.join(values['move_dest_ids'].mapped('name'))
        if != line_name:
            return False
        return super()._merge_in_existing_line(
            product_id, product_qty, product_uom, location_id,
            name, origin, values)

class StockRule(models.Model):
    _inherit = 'stock.rule'

    def _make_po_get_domain(self, values, partner):
        """ We want to create one purchase order per origin """
        res = super(StockRule, self)._make_po_get_domain(values, partner)
        if 'move_dest_ids' in values:
            origin = ', '.join(values['move_dest_ids'].mapped('origin'))
            res += (('origin', '=', origin),)
        return res

    def _prepare_purchase_order_line(
            self, product_id, product_qty, product_uom,
            values, po, partner):
        """ Replace the name with the name in the destination movement,
            this way we translate custom attribute values """
        res = super()._prepare_purchase_order_line(
            product_id, product_qty, product_uom, values, po, partner)
        # Copy name from move_ids, if available
        if 'move_dest_ids' in values:
            name = ', '.join(values['move_dest_ids'].mapped('name'))
            if name:
                res.update({'name': name})
        # Copy name from sale order (needed for dropshipping)
        elif 'sale_line_id' in values:
            sol_id = self.env['sale.order.line'].browse(values['sale_line_id'])
            if sol_id:
        return res


Iván Todorovich

El vie., 13 nov. 2020 a las 11:58, Radovan Skolnik (<>) escribió:
Hello Daniel,

but isn't this used for Services only? I have tried it but it never gets 
called with Products. With Products the flow goes through Procurements.

Best regards


On piatok 13. novembra 2020 15:46:48 CET Daniel Reis wrote:

> Hello,


> You can extend the "_purchase_service_prepare_order_values" method,

> originally declared at addons/sale_purchase/models/

> That prepares the data used to create the POL.


> Thanks

> Daniel


> On 13/11/2020 14:37, Radovan Skolnik

> wrote:



> Hello,

> for our customers we offer standard products but also one-off custom-made

> stuff that we order from our suppliers. These are for example special

> tables with individual dimensions for each project.

> So we have a "template" product (not in the Odoo meaning) that we put into

> Sale Order and in the special SOL field we specify the dimensions. Now if

> the customer accepts the offer, Purchase Order is automatically created as

> we have MTO setup. We do not group POs nor POLs, so each SOL gets its own

> POL. Now how would I be able to propagate contents of that special SOL

> field into its apropriate POL? Or should I use any other approach?

> Thank you very much. Best regards

> Radovan Skolnik



> _______________________________________________

> Mailing-List: [1]

> Post to: [2]

> Unsubscribe: [3]





> _______________________________________________

> Mailing-List: [4]

> Post to:

> Unsubscribe: [5]




> [1]

> [2]

> [3]

> [4]

> [5]

Post to: