summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-08-14 11:07:44 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-08-14 11:07:44 +0700
commit0831a8dc838f7e6bcf184b3ba9e42fc45c3e4f20 (patch)
treece5149e5ea0f029e3bde0cc77abd435973b49e69
parent1845bfdd4e3bd693d691e505b3dc398c028b7e1b (diff)
another checkpoint again
-rw-r--r--indoteknik_custom/models/sale_order_line.py81
1 files changed, 46 insertions, 35 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index af3b4adc..52069d62 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -1,6 +1,6 @@
from odoo import fields, models, api, _
from odoo.exceptions import UserError
-from datetime import datetime
+from datetime import datetime, timedelta
class SaleOrderLine(models.Model):
@@ -125,38 +125,37 @@ class SaleOrderLine(models.Model):
# self.purchase_price = price
# self.purchase_tax_id = taxes
- def _calculate_selling_price(self):
- rec_purchase_price, rec_taxes, rec_vendor_id = self._get_purchase_price(self.product_id)
- state = ['sale', 'done']
- last_so = self.env['sale.order.line'].search([
- ('order_id.partner_id.id', '=', self.order_id.partner_id.id),
- ('product_id.id', '=', self.product_id.id),
- ('order_id.state', 'in', state)
- ], limit=1, order='create_date desc')
- # if rec_vendor_id == self.vendor_id and rec_purchase_price == last_so.purchase_price:
- # selling_price = last_so.price_unit
- # tax_id = last_so.tax_id
- if rec_vendor_id == self.vendor_id and rec_purchase_price != last_so.purchase_price:
- if rec_taxes.price_include:
- selling_price = (rec_purchase_price/1.11) / (1-(last_so.line_item_margin / 100))
- else:
- selling_price = rec_purchase_price / (1-(last_so.line_item_margin / 100))
- tax_id = last_so.tax_id
- elif rec_vendor_id != last_so.vendor_id:
- last_so = self.env['sale.order.line'].search([
- ('order_id.partner_id.id', '=', self.order_id.partner_id.id),
- ('product_id.id', '=', self.product_id.id),
- ('state', 'in', state),
- ('vendor_id', '=', rec_vendor_id)
- ], limit=1, order='order_id.date_order desc')
- selling_price = last_so.price_unit
- tax_id = last_so.tax_id
- else:
- selling_price = last_so.price_unit
- tax_id = last_so.tax_id
- self.price_unit = selling_price
- self.tax_id = tax_id
- print(1)
+ # def _calculate_selling_price(self):
+ # rec_purchase_price, rec_taxes, rec_vendor_id = self._get_purchase_price(self.product_id)
+ # state = ['sale', 'done']
+ # last_so = self.env['sale.order.line'].search([
+ # ('order_id.partner_id.id', '=', self.order_id.partner_id.id),
+ # ('product_id.id', '=', self.product_id.id),
+ # ('order_id.state', 'in', state)
+ # ], limit=1, order='create_date desc')
+ # # if rec_vendor_id == self.vendor_id and rec_purchase_price == last_so.purchase_price:
+ # # selling_price = last_so.price_unit
+ # # tax_id = last_so.tax_id
+ # if rec_vendor_id == self.vendor_id and rec_purchase_price != last_so.purchase_price:
+ # if rec_taxes.price_include:
+ # selling_price = (rec_purchase_price/1.11) / (1-(last_so.line_item_margin / 100))
+ # else:
+ # selling_price = rec_purchase_price / (1-(last_so.line_item_margin / 100))
+ # tax_id = last_so.tax_id
+ # elif rec_vendor_id != last_so.vendor_id:
+ # last_so = self.env['sale.order.line'].search([
+ # ('order_id.partner_id.id', '=', self.order_id.partner_id.id),
+ # ('product_id.id', '=', self.product_id.id),
+ # ('state', 'in', state),
+ # ('vendor_id', '=', rec_vendor_id)
+ # ], limit=1, order='order_id.date_order desc')
+ # selling_price = last_so.price_unit
+ # tax_id = last_so.tax_id
+ # else:
+ # selling_price = last_so.price_unit
+ # tax_id = last_so.tax_id
+ # self.price_unit = selling_price
+ # self.tax_id = tax_id
def _get_purchase_price(self, product_id):
purchase_price = self.env['purchase.pricelist'].search(
@@ -177,28 +176,40 @@ class SaleOrderLine(models.Model):
return self._get_valid_purchase_price(purchase_price)
def _get_valid_purchase_price(self, purchase_price):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=365)
+ # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+
price = 0
taxes = ''
vendor_id = ''
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
- if purchase_price.taxes_product_id.type_tax_use == 'purchase':
+ if purchase_price.taxes_product_id.type_tax_use == 'purchase':
price = purchase_price.product_price
taxes = purchase_price.taxes_product_id.id
vendor_id = purchase_price.vendor_id.id
+ if delta_time > human_last_update:
+ price = 0
+ taxes = ''
+ vendor_id = ''
if system_last_update > human_last_update:
if purchase_price.taxes_system_id.type_tax_use == 'purchase':
price = purchase_price.system_price
taxes = purchase_price.taxes_system_id.id
vendor_id = purchase_price.vendor_id.id
+ if delta_time > system_last_update:
+ price = 0
+ taxes = ''
+ vendor_id = ''
return price, taxes, vendor_id
@api.onchange('product_id')
def product_id_change(self):
- # TODO need to change purchase price logic @stephan
+ # need to change purchase price logic @stephan
super(SaleOrderLine, self).product_id_change()
for line in self:
if line.product_id and line.product_id.type == 'product':