diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/__init__.py b/__init__.py old mode 100644 new mode 100755 diff --git a/__manifest__.py b/__manifest__.py old mode 100644 new mode 100755 diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc index 51944ea..c70c5c7 100644 Binary files a/__pycache__/__init__.cpython-312.pyc and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/__manifest__.cpython-312.pyc b/__pycache__/__manifest__.cpython-312.pyc old mode 100644 new mode 100755 diff --git a/models/__init__.py b/models/__init__.py old mode 100644 new mode 100755 diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 4c1b0f4..d305782 100644 Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/account_move_line.cpython-312.pyc b/models/__pycache__/account_move_line.cpython-312.pyc index d9c8af6..e1c1164 100644 Binary files a/models/__pycache__/account_move_line.cpython-312.pyc and b/models/__pycache__/account_move_line.cpython-312.pyc differ diff --git a/models/account_move_line.py b/models/account_move_line.py old mode 100644 new mode 100755 index b80a289..6570e15 --- a/models/account_move_line.py +++ b/models/account_move_line.py @@ -104,3 +104,50 @@ class AccountMoveLine(models.Model): new_price_unit = derived_price_subtotal / line.quantity line.price_unit = new_price_unit + + def write(self, vals): + """ + Override write to sync changes to linked Purchase Order Line. + """ + res = super(AccountMoveLine, self).write(vals) + + # Check if we need to sync + if 'price_unit' in vals or 'quantity' in vals: + for line in self: + # Only for vendor bills and if linked to a PO line + if line.move_id.move_type in ('in_invoice', 'in_refund') and line.purchase_line_id: + po_line = line.purchase_line_id + + # 1. Sync Price + # Convert bill price (in bill currency) to PO currency + bill_currency = line.currency_id or line.move_id.currency_id + po_currency = po_line.currency_id or po_line.order_id.currency_id + price_unit = line.price_unit + + if bill_currency and po_currency and bill_currency != po_currency: + price_unit = bill_currency._convert( + price_unit, + po_currency, + line.company_id, + line.move_id.invoice_date or fields.Date.today() + ) + + # Convert Price to PO UoM if needed + if line.product_uom_id and po_line.product_uom and line.product_uom_id != po_line.product_uom: + price_unit = line.product_uom_id._compute_price(price_unit, po_line.product_uom) + + # 2. Sync Quantity + # Convert bill qty (in bill UoM) to PO UoM + product_qty = line.quantity + if line.product_uom_id and po_line.product_uom and line.product_uom_id != po_line.product_uom: + product_qty = line.product_uom_id._compute_quantity(product_qty, po_line.product_uom) + + # Update PO Line + # We update both to ensure consistency + po_line.write({ + 'price_unit': price_unit, + 'product_qty': product_qty, + }) + + return res + diff --git a/tests/INTEGRATION_TESTS.md b/tests/INTEGRATION_TESTS.md old mode 100644 new mode 100755 diff --git a/tests/__init__.py b/tests/__init__.py old mode 100644 new mode 100755 diff --git a/tests/run_edge_case_tests.py b/tests/run_edge_case_tests.py old mode 100644 new mode 100755 diff --git a/tests/run_integration_tests.py b/tests/run_integration_tests.py old mode 100644 new mode 100755 diff --git a/tests/run_price_total_test.py b/tests/run_price_total_test.py old mode 100644 new mode 100755 diff --git a/tests/run_property_test.py b/tests/run_property_test.py old mode 100644 new mode 100755 diff --git a/tests/run_view_tests.py b/tests/run_view_tests.py old mode 100644 new mode 100755 diff --git a/tests/test_decimal_precision_property.py b/tests/test_decimal_precision_property.py old mode 100644 new mode 100755 diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py old mode 100644 new mode 100755 diff --git a/tests/test_integration.py b/tests/test_integration.py old mode 100644 new mode 100755 diff --git a/tests/test_price_subtotal_property.py b/tests/test_price_subtotal_property.py old mode 100644 new mode 100755 diff --git a/tests/test_price_total_property.py b/tests/test_price_total_property.py old mode 100644 new mode 100755 diff --git a/tests/test_view_configuration.py b/tests/test_view_configuration.py old mode 100644 new mode 100755 diff --git a/views/.gitkeep b/views/.gitkeep old mode 100644 new mode 100755 diff --git a/views/account_move_views.xml b/views/account_move_views.xml old mode 100644 new mode 100755