summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-06 15:53:19 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-06 15:53:19 +0700
commitedb3c1c80931078d40a8f56149aeca9efdcdc07d (patch)
tree301f863f53c4868a31a4e943d520e97d10998827
parentbc28a47b83eb481f52c89b0f0fa5a13a851fbc21 (diff)
change request purchasing job
-rw-r--r--indoteknik_custom/models/automatic_purchase.py28
-rw-r--r--indoteknik_custom/views/automatic_purchase.xml1
2 files changed, 17 insertions, 12 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 4161d895..94dd9cdf 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -284,7 +284,7 @@ class AutomaticPurchase(models.Model):
purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1)
vendor_id = purchase_pricelist.vendor_id
- price = self._get_valid_purchase_price(purchase_pricelist)
+ price, taxes = self._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)
self.env['automatic.purchase.line'].create([{
@@ -294,6 +294,7 @@ class AutomaticPurchase(models.Model):
'qty_available': qty_available,
'partner_id': vendor_id.id,
'last_price': price,
+ 'taxes_id': taxes,
'subtotal': qty_purchase * price,
'last_order_id': last_po_line.order_id.id,
'last_orderline_id': last_po_line.id,
@@ -414,17 +415,19 @@ class AutomaticPurchase(models.Model):
self.notification = "Automatic PO Created %s Lines" % count
def _get_valid_purchase_price(self, purchase_price):
- p_price = 0
- if purchase_price.system_price > 0 and purchase_price.product_price > 0:
- if purchase_price.human_last_update > purchase_price.system_last_update:
- p_price = purchase_price.product_price
- else:
- p_price = purchase_price.system_price
- elif purchase_price.system_price > 0 and purchase_price.product_price == 0:
- p_price = purchase_price.system_price
- elif purchase_price.system_price == 0 and purchase_price.product_price > 0:
- p_price = purchase_price.product_price
- return p_price
+ price = 0
+ taxes = None
+ human_last_update = purchase_price.human_last_update or datetime.min
+ system_last_update = purchase_price.system_last_update or datetime.min
+
+ if system_last_update > human_last_update:
+ price = purchase_price.system_price
+ taxes = purchase_price.taxes_system_id.id
+ else:
+ price = purchase_price.product_price
+ taxes = purchase_price.taxes_product_id.id
+
+ return price, taxes
class AutomaticPurchaseLine(models.Model):
@@ -447,6 +450,7 @@ class AutomaticPurchaseLine(models.Model):
current_po_id = fields.Many2one('purchase.order', string='Current')
current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line')
brand_id = fields.Many2one('x_manufactures', string='Brand')
+ taxes_id = fields.Many2one('account.tax', string='Taxes')
@api.onchange('last_price', 'qty_purchase')
def _calculate_subtotal(self):
diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml
index edf966d9..244d1caa 100644
--- a/indoteknik_custom/views/automatic_purchase.xml
+++ b/indoteknik_custom/views/automatic_purchase.xml
@@ -30,6 +30,7 @@
<field name="qty_purchase"/>
<field name="partner_id"/>
<field name="last_price"/>
+ <field name="taxes_id"/>
<field name="subtotal"/>
<field name="last_order_id" readonly="1" optional="hide"/>
<field name="current_po_line_id" readonly="1" optional="hide"/>