Skip to content

Conversation

@P-H-Phuc
Copy link
Owner

@P-H-Phuc P-H-Phuc commented Nov 24, 2025

Krunal and others added 11 commits November 20, 2025 10:06
* [ADD] Added new feature to sort Computed PO lines

* [ADD] Added new feauture to see Computed purchase order lines, Improved fr translations
Currently translated at 100.0% (178 of 178 strings)

Translation: foodcoops-12.0/foodcoops-12.0-purchase_compute_order
Translate-URL: https://translate.druidoo.io/projects/foodcoops-12-0/foodcoops-12-0-purchase_compute_order/fr/
Currently translated at 100.0% (178 of 178 strings)

Translation: foodcoops-12.0/foodcoops-12.0-purchase_compute_order
Translate-URL: https://translate.druidoo.io/projects/foodcoops-12-0/foodcoops-12-0-purchase_compute_order/fr/

[FIX] Order of lines in Calculated Purchase Order

[FIX] CPO performance issue (S#26472)

[FIX] S#26688:  Cann’t order from Viome

[ADD] S#T34632 - Delivery Categories

[ADD] F#T59775 - Minimum Quantity for products in Calculated purchase order

F#T60423 - Add column Nb. Package MAX

[ADD] F#T60745 - Add Shelf Life information

[UPD] F#T60886 - Save Purchase Target in CPO after order PO created

[UPD] F#T60885 - Adjustment to Product History Pop-up in CPO

[UPD] F#T61877 - [SQQ-VDM] Missing translation in FR
@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch from b0fd57a to 7317a54 Compare November 24, 2025 09:04
Copy link

@nguyenminhchien nguyenminhchien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests failed
image

Copy link

@nguyenminhchien nguyenminhchien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add product_packaging_id to the flow: product.supplierinfo => CPO => PO =>...
  • Remember to show the package things for the group product.group_stock_packaging only.

compute="_compute_subtotal_price",
digits="Product Price",
)
package_qty = fields.Float("Package quantity")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add new field product_packaging_id m2o to product.packaging
  • package_qty = fields.Float(related="product_packaging_id.qty", store=True,...)

<field name="uom_id" />
<field name="stock_duration" />
<field name="cpo_state" invisible="1" />
<field name="purchase_qty_package" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Show product_packaging_id to the UI.
  • Add groups="product.group_stock_packaging" for all the fields related to the package

@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch from 7317a54 to 5f89bf6 Compare November 28, 2025 08:00
@P-H-Phuc P-H-Phuc changed the title [18.0[MIG] purchase_compute_order: Migration to 18.0 [18.0][MIG] purchase_compute_order: Migration to 18.0 Dec 2, 2025
Copy link

@nguyenminhchien nguyenminhchien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests still failed from fresh db:

 
2025-12-04 02:28:28,667 22467 INFO v18c_purchase_compute_order odoo.addons.purchase_compute_order.tests.test_purchase_compute_order: Starting TestPurchaseComputeOrder.test_003_make_purchase_order ... 
2025-12-04 02:28:28,721 22467 INFO v18c_purchase_compute_order odoo.addons.purchase_compute_order.tests.test_purchase_compute_order: ====================================================================== 
2025-12-04 02:28:28,721 22467 ERROR v18c_purchase_compute_order odoo.addons.purchase_compute_order.tests.test_purchase_compute_order: ERROR: TestPurchaseComputeOrder.test_003_make_purchase_order
Traceback (most recent call last):
  File "/home/chien/code/oca/purchase-workflow/18.0/purchase_compute_order/tests/test_purchase_compute_order.py", line 68, in test_003_make_purchase_order
    self.cmp_purchase_order.compute_purchase_quantities()
  File "/home/chien/code/oca/purchase-workflow/18.0/purchase_compute_order/models/computed_purchase_order.py", line 492, in compute_purchase_quantities
    return cpo._compute_purchase_quantities_days()
  File "/home/chien/code/oca/purchase-workflow/18.0/purchase_compute_order/models/computed_purchase_order.py", line 369, in _compute_purchase_quantities_days
    line.purchase_qty_package = quantity / package_qty
ZeroDivisionError: float division by zero

Copy link

@nguyenminhchien nguyenminhchien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add product_packaging_id to the flow: product.supplierinfo => CPO => PO =>...

You missed this point.
I cannot test further without that feature.

<field name="purchase_qty" />
<field name="product_price_inv" />
<field name="discount_inv" />
<field name="price_policy" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name="price_policy" />
<field name="price_policy" groups="product.group_stock_packaging"/>

<field name="purchase_qty" readonly="1" />
<field name="product_price_inv" readonly="1" />
<field name="discount_inv" readonly="1" />
<field name="price_policy" readonly="1" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name="price_policy" readonly="1" />
<field name="price_policy" readonly="1" groups="product.group_stock_packaging" />

</div>
<field name="product_price_inv" />
<field name="discount_inv" />
<field name="price_policy" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name="price_policy" />
<field name="price_policy" groups="product.group_stock_packaging"/>

required=True,
help="""This comes from the product form.""",
)
package_qty = fields.Float(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wherever package_qty is, add product_packaging_id and change package_qty to be a related field.

"product_code": line.product_code,
"product_name": line.product_name,
"product_uom": line.uom_po_id.id,
"package_qty": line.package_qty,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"package_qty": line.package_qty,
"product_packaging_id": line.product_packaging_id,

"product_name": line.product_name,
"product_code": line.product_code,
"product_uom": line.product_uom.id,
"package_qty": line.package_qty,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"package_qty": line.package_qty,
"product_packaging_id": line.product_packaging_id,

@nguyenminhchien
Copy link

I just made a change in https://github.com/OCA/purchase-workflow/pull/2892
Please pull this to have the latest codebase.

@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch 2 times, most recently from 38c3b6e to c7a2201 Compare December 8, 2025 08:20
<field name="product_code_inv" readonly="1" />
<field
name="product_code_inv"
string="Supplier Product Code"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove readonly="1"?

<field name="incoming_qty" string="Incoming" />
<field
name="displayed_average_consumption"
readonly="1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove readonly="1"?

name="purchase_qty_package"
attrs="{'readonly':
[('cpo_state', '!=', 'draft')]}"
readonly="cpo_state != 'draft'"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly="cpo_state != 'draft' or not product_packaging_id"

User needs to choose the packaging first.

readonly="1"
groups="product.group_stock_packaging"
/>
<field name="purchase_qty" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly="cpo_state != 'draft' or product_packaging_id"

"product_name": psi.product_name,
"product_price": psi.base_price,
"price_policy": psi.price_policy,
"package_qty": psi.package_qty or psi.min_qty,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"package_qty": psi.package_qty or psi.min_qty,
"product_packaging_id": psi.product_packaging_id.id,

psi_ids = psi_obj.search(
[
("partner_id", "=", partner_id),
("product_tmpl_id", "=", product_tmpl_id),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a domain for packaging id of the cpol if any.

"product_name": cpol.product_name,
"product_code": cpol.product_code,
"product_uom": cpol.uom_po_id.id,
"package_qty": cpol.package_qty_inv,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"package_qty": cpol.package_qty_inv,
"product_packaging_id": cpol.product_packaging_id.id,

It's seem that the button call this action will never be called. But just in case.

- the theoretical duration of the stock, based on the precedent figures.

- Unlink the products you don't want to buy anymore to this supplier (this only deletes the product_supplierinfo)
- Add new products you want to buy and link them (this creates a product_supplierinfo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line since it cannot be added now. Most of the fields are readonly: Supplier product code, product, price,..


- Unlink the products you don't want to buy anymore to this supplier (this only deletes the product_supplierinfo)
- Add new products you want to buy and link them (this creates a product_supplierinfo)
- Modify any information about the products: supplier product_code, supplier product_name, purchase price, package quantity, purchase UoM.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line, these fields are readonly now.
Btw, check and update this file to adapt with the current behaviors.

)
uom_id = fields.Many2one(related="product_id.uom_id")
product_code = fields.Char(
"Supplier Product Code",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see that we have some duplicated fields:

  • product_code vs product_code_inv
  • product_name vs product_name_inv
  • product_price vs product_price_inv
  • discount vs discount_inv

inv here is the short word of inverse. These *_inv fields were allowed the user to update the values of Product.supplierinfo. But, they're readonly now. Means that we don't need them anymore.

  • Remove them all.
  • Change these fields to related fields (NO store):
    • product_code: psi_id.product_code
    • product_name: psi_id.product_name
    • product_price: psi_id.price
    • discount: psi_id.discount
    • price_policy: psi_id.price_policy
    • uom_po_id: psi_id.uom_po_id

@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch 3 times, most recently from 1241867 to 1176b9e Compare December 10, 2025 07:21
Copy link

@nguyenminhchien nguyenminhchien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error right after opening a CPO record:
image

)
self.psi_id = valid_psi.id

@api.depends("purchase_qty_package", "package_qty")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not depend on package_qty since it's a related field. This could lead to unexpected update behavior.
Depends on product_packaging_id instead.
Check for other related fields: price_policy, discount,...

@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch from 1176b9e to 1ec9fbe Compare December 10, 2025 08:27
@api.depends(
"purchase_qty", "psi_id.price", "psi_id.price_policy", "psi_id.discount"
)
def _compute_subtotal_price(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtotal is incorrect:

  • price_policy == "package": subtotal = (Number of package) * Base price (from PSI)
  • Else: Subtotal = (Qty to purchase) * Base price (from PSI)
  • Take the Discount into account.
  • Double check to make sure the PO created from CPO, having the same subtotal then.
image

/>
<field name="stock_duration" />
<field
name="product_packaging_id"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add context to set the product when adding a new package here.

line_values = {
"name": line_name,
"product_qty": line.purchase_qty,
"package_qty": line.package_qty,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"package_qty": line.package_qty,
"product_packaging_id": line.product_packaging_id.id,

@P-H-Phuc P-H-Phuc force-pushed the 18.0-mig-purchase_compute_order branch from 1ec9fbe to ead5d8b Compare December 10, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants