commit a13e7af0f68ce06221a5899a81105bba454b2177 Author: admin.suherdy Date: Wed Dec 17 15:50:16 2025 +0700 first commit diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..7bfdaf9 --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'Sale Order Tracking', + 'version': '18.0.1.0.0', + 'category': 'Sales', + 'summary': 'Track changes in Sale Orders and Lines', + 'description': """ + This module tracks: + 1. Customer changes in Sale Order. + 2. Product and Quantity changes in Sale Order Lines. + 3. Addition and Removal of Sale Order Lines. + """, + 'author': 'Antigravity', + 'depends': ['sale_management'], + 'data': [], + 'installable': True, + 'application': False, + 'license': 'LGPL-3', +} diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..a295ffa Binary files /dev/null and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..2d7ee6c --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order +from . import sale_order_line diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..b51a986 Binary files /dev/null and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/sale_order.cpython-312.pyc b/models/__pycache__/sale_order.cpython-312.pyc new file mode 100644 index 0000000..5deb88f Binary files /dev/null and b/models/__pycache__/sale_order.cpython-312.pyc differ diff --git a/models/__pycache__/sale_order_line.cpython-312.pyc b/models/__pycache__/sale_order_line.cpython-312.pyc new file mode 100644 index 0000000..9a4992b Binary files /dev/null and b/models/__pycache__/sale_order_line.cpython-312.pyc differ diff --git a/models/sale_order.py b/models/sale_order.py new file mode 100644 index 0000000..c341263 --- /dev/null +++ b/models/sale_order.py @@ -0,0 +1,6 @@ +from odoo import models, fields + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + partner_id = fields.Many2one(tracking=True) diff --git a/models/sale_order_line.py b/models/sale_order_line.py new file mode 100644 index 0000000..3716867 --- /dev/null +++ b/models/sale_order_line.py @@ -0,0 +1,58 @@ +from odoo import models, fields, api + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + @api.model_create_multi + def create(self, vals_list): + lines = super(SaleOrderLine, 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_uom_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_uom_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_uom_qty': line.product_uom_qty, + } + + result = super(SaleOrderLine, 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_uom_qty' in vals: + new_qty = line.product_uom_qty + old_qty = old_data['product_uom_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_uom_qty})" + line.order_id.message_post(body=msg) + return super(SaleOrderLine, self).unlink()