Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odgovori
7197 Prikazi

Hii,

I created a Purchase Order from Sales Order. Item is set MTO.  

I am developing a PO PDF Report.  One Purchase Order Line want to show related sales order line info like Qty etc.

There are two field sale_order_id and sale_line_id in purchase_order_line model, but these are always empty.

  <t t-foreach="o.order_line t-as="line">
        <tr>
           <td>
               SO: <span t-field="line.sale_order_id" /><br/> 
               Line: <span t-field="line.sale_line_id" />
            </td>
	</tr>
</t>

How to get/show sales line info on purchase line if Purchase is Make to Order?

Thanks,

Avatar
Opusti
Best Answer

I am looking for the same functionality. What you have found is being used in module "Sale Purchase" (sale_purchase). This is its description:

Allows the outsourcing of services. This module allows one to sell services provided by external providers and will automatically generate purchase orders directed to the service seller.

This module adds "Purchase Automatically" option to Products of type Service. When it is checked and there is Vendor set for it, upon putting it into Sale Order Line and that Sale Order is confirmed, it will automatically create/update Purchase Order and create Purchase Order Line and will link those Lines together and origin attribute (Source documents) is updated. There is also a smart button (which is currently disabled in 13.0 - I created PR to enable it again: https://github.com/odoo/odoo/pull/51874) which allows you to open linked POs from SO.


However in case of MTO (and checking Buy option) this goes through "Purchase Stock" (purchase_stock) module where PO and PO Lines are created, origin attribute (Source documents) is updated but the records are not linked together. That's why these attributes are always empty.


I am looking for a way to do this but in sale_purchase the PO/POLs are created directly from SO/SOLs so there is no problem linking them. However in purchase_stock the context is different - the PO/POLs are created somewhere in context of StockRule in the method _run_buy(self, procurements) where the originating SO/SOLs are not easily accessible (at least for me). But I need this so will look for an option...

Avatar
Opusti

Have you found a solution?

Best Answer

Did you guys found a solution for this ?
Make the below server action on sale\\.order\\.line

if\ record:
 \  \ sale_order\ =\ record\.order_id\.procurement_group_id\.stock_move_ids\.filtered\(lambda\ x:\ x\.product_id\.id\ ==\ record\.product_id\.id\)\.move_orig_ids\.filtered\(lambda\ x:\ x\.product_id\.id\ ==\ record.product_id.id)
    if sale_order and sale_order.purchase_line_id:
        po_line_id = sale_order.purchase_line_id
        if po_line_id and not po_line_id.sale_line_id :
            po_line_id.write({'sale_line_id':record.id})

Avatar
Opusti
Best Answer

Hi,

Checkout this app: https://apps.odoo.com/apps/modules/13.0/split_po_line/

Avatar
Opusti
Avtor

Please help the community by sharing the code. Thank You.

Best Answer

but it from standard comes source document and procurement group.

Avatar
Opusti
Avtor

run this query

select * from procurement_group where name like 'PO%'

sale_id field is all empty