diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-08-02 10:50:53 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-08-02 10:50:53 +0700 |
| commit | 9dc7af549efd30d2afa9568480607592d42ca04a (patch) | |
| tree | 6a679457b0b9af144998c1aed8fc1df8abfe7b08 /indoteknik_custom/models/sale_order.py | |
| parent | 11261e1b5ebd8a0d139abdbf23e985a8fb470eac (diff) | |
test case
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 44e4a886..d6f04607 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -834,5 +834,44 @@ class SaleOrder(models.Model): } } + def calculate_selling_price(self): + for order_line in self.order_line: + rec_purchase_price, rec_taxes, rec_vendor_id = order_line._get_purchase_price(order_line.product_id) + state = ['sale', 'done'] + last_so = self.env['sale.order.line'].search([ + ('order_id.partner_id.id', '=', order_line.order_id.partner_id.id), + ('product_id.id', '=', order_line.product_id.id), + ('order_id.state', 'in', state), + ('id', '!=', order_line.id) + ], 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 == order_line.vendor_id.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 + discount = 0 + elif rec_vendor_id != last_so.vendor_id.id: + last_so = self.env['sale.order.line'].search([ + ('order_id.partner_id.id', '=', order_line.order_id.partner_id.id), + ('product_id.id', '=', order_line.product_id.id), + ('order_id.state', 'in', state), + ('vendor_id', '=', rec_vendor_id), + ('id', '!=', order_line.id) + ], limit=1, order='create_date desc') + selling_price = last_so.price_unit + tax_id = last_so.tax_id + discount = last_so.discount + else: + selling_price = last_so.price_unit + tax_id = last_so.tax_id + discount = last_so.discount + order_line.price_unit = selling_price + order_line.tax_id = tax_id + order_line.discount = discount + print(1) |
