diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-04-29 09:24:25 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-04-29 09:24:25 +0700 |
| commit | 074b99031f5123976bb67aab1cf1a6286464e724 (patch) | |
| tree | 2809d42a13b35c42ec00d93a40a414e7713a1bc2 /indoteknik_custom/models/purchase_order_line.py | |
| parent | b5a42eda62ae2b3536a072b9cb21a61e91a7b49a (diff) | |
| parent | ca03f0119e33dd62adbf998106378d8e0f4096b6 (diff) | |
Merge branch 'production' into feature/request-by-abl
Diffstat (limited to 'indoteknik_custom/models/purchase_order_line.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index c2e7a4c7..2eeb7d3e 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -40,6 +40,50 @@ 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('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.sale_line_id.purchase_price = line.price_unit + + @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: |
