summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-04-22 09:24:14 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-04-22 09:24:14 +0700
commit9206062d88d5c243351d334cb8ade3ddc51d22ff (patch)
tree965e71a9c3fba7d2d1c8bdf3d9f508a4db83b206
parent391d7a3b93eff3eabee371b35ec5287e1f0afdd2 (diff)
add new fiture to purchasing job
-rw-r--r--indoteknik_custom/models/automatic_purchase.py3
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py34
-rw-r--r--indoteknik_custom/views/automatic_purchase.xml2
3 files changed, 37 insertions, 2 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 32a7d9dd..94cf686e 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -338,6 +338,7 @@ class AutomaticPurchase(models.Model):
purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1)
vendor_id = purchase_pricelist.vendor_id
+ taxes = ''
price, taxes = automatic_purchase._get_valid_purchase_price(purchase_pricelist)
last_po_line = self.env['purchase.order.line'].search([('product_id', '=', job.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1)
@@ -467,7 +468,7 @@ class AutomaticPurchase(models.Model):
def _get_valid_purchase_price(self, purchase_price):
price = 0
- taxes = None
+ taxes = ''
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
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:
diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml
index 360fdd16..a505daa5 100644
--- a/indoteknik_custom/views/automatic_purchase.xml
+++ b/indoteknik_custom/views/automatic_purchase.xml
@@ -30,7 +30,7 @@
<field name="qty_max"/>
<field name="qty_available"/>
<field name="qty_purchase"/>
- <field name="partner_id"/>
+ <field name="partner_id" required="1"/>
<field name="last_price"/>
<field name="taxes_id"/>
<field name="subtotal"/>