first commit

This commit is contained in:
Suherdy Yacob 2026-01-02 17:01:03 +07:00
commit 77ff4d5f81
7 changed files with 76 additions and 0 deletions

1
__init__.py Normal file
View File

@ -0,0 +1 @@
from . import models

16
__manifest__.py Normal file
View File

@ -0,0 +1,16 @@
{
'name': 'Purchase Order Tracking',
'version': '1.0',
'category': 'Purchase',
'summary': 'Track changes in Purchase Order Lines',
'description': """
This module tracks changes in Purchase Order Lines (Product and Quantity)
and posts notifications to the Purchase Order chatter.
""",
'author': 'Suherdy Yacob',
'depends': ['purchase'],
'data': [],
'installable': True,
'application': False,
'license': 'LGPL-3',
}

Binary file not shown.

1
models/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import purchase_order_line

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,58 @@
from odoo import models, fields, api
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
@api.model_create_multi
def create(self, vals_list):
lines = super(PurchaseOrderLine, self).create(vals_list)
for line in lines:
if line.order_id:
# Log creation
msg = f"Line added: {line.product_id.display_name} (Qty: {line.product_qty})"
line.order_id.message_post(body=msg)
return lines
def write(self, vals):
# Capture old values for tracking
changes = {}
track_fields = ['product_id', 'product_qty']
# Only track if relevant fields are being modified
if any(f in vals for f in track_fields):
for line in self:
changes[line.id] = {
'product_id': line.product_id,
'product_qty': line.product_qty,
}
result = super(PurchaseOrderLine, self).write(vals)
for line in self:
if line.id in changes:
old_data = changes[line.id]
# Track Product Change
if 'product_id' in vals:
new_product = line.product_id
old_product = old_data['product_id']
if old_product != new_product:
msg = f"Product changed on line: {old_product.display_name or 'None'} -> {new_product.display_name or 'None'}"
line.order_id.message_post(body=msg)
# Track Quantity Change
if 'product_qty' in vals:
new_qty = line.product_qty
old_qty = old_data['product_qty']
if old_qty != new_qty:
msg = f"Quantity changed for {line.product_id.display_name}: {old_qty} -> {new_qty}"
line.order_id.message_post(body=msg)
return result
def unlink(self):
for line in self:
if line.order_id and line.product_id:
msg = f"Line removed: {line.product_id.display_name} (Qty: {line.product_qty})"
line.order_id.message_post(body=msg)
return super(PurchaseOrderLine, self).unlink()