add synchronization with Purcahse Order, change on vendor bills will change PO

This commit is contained in:
Suherdy Yacob 2026-01-08 09:29:05 +07:00
parent da54e2585b
commit 961f81a806
25 changed files with 47 additions and 0 deletions

0
CHANGELOG.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
__init__.py Normal file → Executable file
View File

0
__manifest__.py Normal file → Executable file
View File

Binary file not shown.

0
__pycache__/__manifest__.cpython-312.pyc Normal file → Executable file
View File

0
models/__init__.py Normal file → Executable file
View File

47
models/account_move_line.py Normal file → Executable file
View File

@ -104,3 +104,50 @@ class AccountMoveLine(models.Model):
new_price_unit = derived_price_subtotal / line.quantity new_price_unit = derived_price_subtotal / line.quantity
line.price_unit = new_price_unit 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

0
tests/INTEGRATION_TESTS.md Normal file → Executable file
View File

0
tests/__init__.py Normal file → Executable file
View File

0
tests/run_edge_case_tests.py Normal file → Executable file
View File

0
tests/run_integration_tests.py Normal file → Executable file
View File

0
tests/run_price_total_test.py Normal file → Executable file
View File

0
tests/run_property_test.py Normal file → Executable file
View File

0
tests/run_view_tests.py Normal file → Executable file
View File

0
tests/test_decimal_precision_property.py Normal file → Executable file
View File

0
tests/test_edge_cases.py Normal file → Executable file
View File

0
tests/test_integration.py Normal file → Executable file
View File

0
tests/test_price_subtotal_property.py Normal file → Executable file
View File

0
tests/test_price_total_property.py Normal file → Executable file
View File

0
tests/test_view_configuration.py Normal file → Executable file
View File

0
views/.gitkeep Normal file → Executable file
View File

0
views/account_move_views.xml Normal file → Executable file
View File