diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-22 09:24:14 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-22 09:24:14 +0700 |
| commit | 9206062d88d5c243351d334cb8ade3ddc51d22ff (patch) | |
| tree | 965e71a9c3fba7d2d1c8bdf3d9f508a4db83b206 /indoteknik_custom/models/purchase_order_line.py | |
| parent | 391d7a3b93eff3eabee371b35ec5287e1f0afdd2 (diff) | |
add new fiture to purchasing job
Diffstat (limited to 'indoteknik_custom/models/purchase_order_line.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 34 |
1 files changed, 34 insertions, 0 deletions
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: |
