From 9206062d88d5c243351d334cb8ade3ddc51d22ff Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 22 Apr 2024 09:24:14 +0700 Subject: add new fiture to purchasing job --- indoteknik_custom/models/purchase_order_line.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'indoteknik_custom/models/purchase_order_line.py') diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index c2e7a4c7..b9c4011e 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -40,6 +40,40 @@ class PurchaseOrderLine(models.Model): delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini') is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty') + @api.constrains('product_qty') + def constrains_product_qty(self): + for line in self: + qty_po = 0 + matches_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', line.order_id.id), + ('product_id', '=', line.product_id.id), + ]) + + if not matches_so: + continue + + for matches in matches_so: + qty_po += matches.qty_po + + if qty_po == line.product_qty: + continue + + oldest_date_order = min(matches_so.mapped('sale_id.date_order')) + oldest_matches = matches_so.filtered(lambda x: x.sale_id.date_order == oldest_date_order) + matches_to_remove = matches_so - oldest_matches + + if matches_to_remove: + matches_to_remove.unlink() + + def unlink(self): + for line in self: + mathces_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', line.order_id.id), + ('product_id', '=', line.product_id.id), + ]) + mathces_so.unlink() + return super(PurchaseOrderLine, self).unlink() + def _compute_is_edit_product_qty(self): for line in self: -- cgit v1.2.3 From 68c7f85b0bf7b8eb85f5bbffcfe2bbc8a38b7e4e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 24 Apr 2024 13:45:43 +0700 Subject: update purchasing job --- indoteknik_custom/models/purchase_order_line.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indoteknik_custom/models/purchase_order_line.py') diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index b9c4011e..93b235d8 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -40,6 +40,16 @@ class PurchaseOrderLine(models.Model): delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini') is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty') + @api.constrains('purchase_price') + def constrains_purchase_price(self): + for line in self: + matches_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', line.order_id.id), + ('product_id', '=', line.product_id.id), + ]) + + line.purchase_price = matches_so.sale_line_id.purchase_price + @api.constrains('product_qty') def constrains_product_qty(self): for line in self: -- cgit v1.2.3 From 0c577a495101b4f8b6034d3fe097a0a53502d9b2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 24 Apr 2024 14:27:15 +0700 Subject: fix bug --- indoteknik_custom/models/purchase_order_line.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models/purchase_order_line.py') diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 93b235d8..624415e3 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -40,15 +40,14 @@ class PurchaseOrderLine(models.Model): delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini') is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty') - @api.constrains('purchase_price') + @api.constrains('price_unit') def constrains_purchase_price(self): - for line in self: - matches_so = self.env['purchase.order.sales.match'].search([ - ('purchase_order_id', '=', line.order_id.id), - ('product_id', '=', line.product_id.id), - ]) + matches_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', self.order_id.id), + ('product_id', '=', self.product_id.id), + ]) - line.purchase_price = matches_so.sale_line_id.purchase_price + matches_so.sale_line_id.purchase_price = self.price_unit @api.constrains('product_qty') def constrains_product_qty(self): -- cgit v1.2.3 From fb23eeec8484031730d8716caf0f8ee0e6a07ed4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 25 Apr 2024 10:53:16 +0700 Subject: fix bug po line --- indoteknik_custom/models/purchase_order_line.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/purchase_order_line.py') diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 624415e3..2eeb7d3e 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -42,12 +42,13 @@ class PurchaseOrderLine(models.Model): @api.constrains('price_unit') def constrains_purchase_price(self): - matches_so = self.env['purchase.order.sales.match'].search([ - ('purchase_order_id', '=', self.order_id.id), - ('product_id', '=', self.product_id.id), - ]) + for line in self: + matches_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', line.order_id.id), + ('product_id', '=', line.product_id.id), + ]) - matches_so.sale_line_id.purchase_price = self.price_unit + matches_so.sale_line_id.purchase_price = line.price_unit @api.constrains('product_qty') def constrains_product_qty(self): -- cgit v1.2.3