From 9dc7af549efd30d2afa9568480607592d42ca04a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 2 Aug 2024 10:50:53 +0700 Subject: test case --- indoteknik_custom/models/sale_order.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') 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) -- cgit v1.2.3 From 56bb6d2f83a2c8dec98160bed397a26007df7450 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 2 Aug 2024 10:51:18 +0700 Subject: fixed test case --- indoteknik_custom/models/sale_order.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d6f04607..2a930a73 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -836,7 +836,7 @@ 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) + rec_purchase_price, rec_taxes_id, 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), @@ -848,10 +848,11 @@ class SaleOrder(models.Model): # 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: + rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) if rec_taxes.price_include: - selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.line_item_margin / 100)) + selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) else: - selling_price = rec_purchase_price / (1 - (last_so.line_item_margin / 100)) + selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) tax_id = last_so.tax_id discount = 0 elif rec_vendor_id != last_so.vendor_id.id: @@ -873,5 +874,3 @@ class SaleOrder(models.Model): order_line.tax_id = tax_id order_line.discount = discount print(1) - - -- cgit v1.2.3 From 7229d06c4d4557fd1e92e3afbda789620f5a2d0c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 2 Aug 2024 15:32:50 +0700 Subject: fix for test case --- indoteknik_custom/models/sale_order.py | 41 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 2a930a73..a4c3d079 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -844,18 +844,8 @@ class SaleOrder(models.Model): ('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: - rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) - if rec_taxes.price_include: - selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) - else: - selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) - tax_id = last_so.tax_id - discount = 0 - elif rec_vendor_id != last_so.vendor_id.id: + + if 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), @@ -863,9 +853,31 @@ class SaleOrder(models.Model): ('vendor_id', '=', rec_vendor_id), ('id', '!=', order_line.id) ], limit=1, order='create_date desc') - selling_price = last_so.price_unit + if rec_purchase_price != last_so.purchase_price: + rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) + if rec_taxes.price_include: + selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) + else: + selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) + tax_id = last_so.tax_id + for tax in tax_id: + if tax.price_include: + selling_price = selling_price + (selling_price*11/100) + else: + selling_price = selling_price + discount = 0 + else: + selling_price = last_so.price_unit + tax_id = last_so.tax_id + discount = last_so.discount + elif rec_vendor_id == order_line.vendor_id.id and rec_purchase_price != last_so.purchase_price: + rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) + if rec_taxes.price_include: + selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) + else: + selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) tax_id = last_so.tax_id - discount = last_so.discount + discount = 0 else: selling_price = last_so.price_unit tax_id = last_so.tax_id @@ -873,4 +885,3 @@ class SaleOrder(models.Model): order_line.price_unit = selling_price order_line.tax_id = tax_id order_line.discount = discount - print(1) -- cgit v1.2.3 From 3cf53a4a6bc09a41bfd39f243a951e21b060c8ca Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 3 Aug 2024 09:04:51 +0700 Subject: fix empty data --- indoteknik_custom/models/sale_order.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index a4c3d079..c5689a79 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -866,10 +866,14 @@ class SaleOrder(models.Model): else: selling_price = selling_price discount = 0 - else: + elif last_so: selling_price = last_so.price_unit tax_id = last_so.tax_id discount = last_so.discount + else: + selling_price = order_line.price_unit + tax_id = order_line.tax_id + discount = order_line.discount elif rec_vendor_id == order_line.vendor_id.id and rec_purchase_price != last_so.purchase_price: rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) if rec_taxes.price_include: @@ -878,10 +882,14 @@ class SaleOrder(models.Model): selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) tax_id = last_so.tax_id discount = 0 - else: + elif last_so: selling_price = last_so.price_unit tax_id = last_so.tax_id discount = last_so.discount + else: + selling_price = order_line.price_unit + tax_id = order_line.tax_id + discount = order_line.discount order_line.price_unit = selling_price order_line.tax_id = tax_id order_line.discount = discount -- cgit v1.2.3 From fa8a40973dee9f4f4cd2d7908e9a1ed4fb75cfaa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 9 Aug 2024 16:53:40 +0700 Subject: add todo --- indoteknik_custom/models/sale_order.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index c5689a79..5e5d76b4 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -835,6 +835,9 @@ class SaleOrder(models.Model): } def calculate_selling_price(self): + # TODO ongkos kirim, biaya pihak ketiga calculate @stephan + # TODO voucher @stephan + # TODO vendor hilanging child di field SO Line @stephan for order_line in self.order_line: rec_purchase_price, rec_taxes_id, rec_vendor_id = order_line._get_purchase_price(order_line.product_id) state = ['sale', 'done'] -- cgit v1.2.3 From 2788396b4b1ccbb83c287f9bba0d52e7799f7b38 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 13 Aug 2024 14:19:02 +0700 Subject: add todo in calculate selling price --- indoteknik_custom/models/sale_order.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5e5d76b4..0be40fd0 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -838,6 +838,10 @@ class SaleOrder(models.Model): # TODO ongkos kirim, biaya pihak ketiga calculate @stephan # TODO voucher @stephan # TODO vendor hilanging child di field SO Line @stephan + # TODO button pindahin @stephan + # TODO last so 1 tahun ke belakang @stephan + # TODO pastikan harga beli 1 tahun ke belakang jg + # TODO counter di klik berapa banyak for order_line in self.order_line: rec_purchase_price, rec_taxes_id, rec_vendor_id = order_line._get_purchase_price(order_line.product_id) state = ['sale', 'done'] @@ -884,6 +888,11 @@ class SaleOrder(models.Model): else: selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) tax_id = last_so.tax_id + for tax in tax_id: + if tax.price_include: + selling_price = selling_price + (selling_price * 11 / 100) + else: + selling_price = selling_price discount = 0 elif last_so: selling_price = last_so.price_unit -- cgit v1.2.3 From 1845bfdd4e3bd693d691e505b3dc398c028b7e1b Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 14 Aug 2024 10:40:12 +0700 Subject: another checkpoint --- indoteknik_custom/models/sale_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 0be40fd0..e71b8ce4 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -837,8 +837,8 @@ class SaleOrder(models.Model): def calculate_selling_price(self): # TODO ongkos kirim, biaya pihak ketiga calculate @stephan # TODO voucher @stephan - # TODO vendor hilanging child di field SO Line @stephan - # TODO button pindahin @stephan + # vendor hilangin child di field SO Line @stephan + # button pindahin @stephan # TODO last so 1 tahun ke belakang @stephan # TODO pastikan harga beli 1 tahun ke belakang jg # TODO counter di klik berapa banyak @@ -890,7 +890,7 @@ class SaleOrder(models.Model): tax_id = last_so.tax_id for tax in tax_id: if tax.price_include: - selling_price = selling_price + (selling_price * 11 / 100) + selling_price = selling_price + (selling_price*11/100) else: selling_price = selling_price discount = 0 -- cgit v1.2.3 From 513d2b473f4fbf7245c35289e2a3215c5da556a6 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 14 Aug 2024 11:47:00 +0700 Subject: finished and ready to use for calculate selling price --- indoteknik_custom/models/sale_order.py | 49 +++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e71b8ce4..5badacba 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -108,6 +108,7 @@ class SaleOrder(models.Model): date_driver_arrival = fields.Datetime(string='Arrival Date', compute='_compute_date_kirim', copy=False) date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") + use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) def _compute_date_kirim(self): for rec in self: @@ -835,37 +836,57 @@ class SaleOrder(models.Model): } def calculate_selling_price(self): - # TODO ongkos kirim, biaya pihak ketiga calculate @stephan + # ongkos kirim, biaya pihak ketiga calculate @stephan # TODO voucher @stephan # vendor hilangin child di field SO Line @stephan # button pindahin @stephan - # TODO last so 1 tahun ke belakang @stephan - # TODO pastikan harga beli 1 tahun ke belakang jg - # TODO counter di klik berapa banyak + # last so 1 tahun ke belakang @stephan + # pastikan harga beli 1 tahun ke belakang jg + # harga yg didapat dari semua kumpulan parent parner dan child nya + # counter di klik berapa banyak @stephan for order_line in self.order_line: + if not order_line.product_id: + continue + current_time = datetime.now() + delta_time = current_time - timedelta(days=365) + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + + # Initialize partners list with parent_id or partner_id + partners = [] + parent_id = self.partner_id.parent_id or self.partner_id + + # Add all child_ids and the parent itself to partners as IDs + partners.extend(parent_id.child_ids.ids) + partners.append(parent_id.id) + rec_purchase_price, rec_taxes_id, 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), + # ('order_id.partner_id.id', '=', order_line.order_id.partner_id.id), + ('order_id.partner_id', 'in', partners), ('product_id.id', '=', order_line.product_id.id), ('order_id.state', 'in', state), - ('id', '!=', order_line.id) + ('id', '!=', order_line.id), + ('order_id.date_order', '>=', delta_time) ], limit=1, order='create_date desc') if 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), + # ('order_id.partner_id.id', '=', order_line.order_id.partner_id.id), + ('order_id.partner_id', 'in', partners), ('product_id.id', '=', order_line.product_id.id), ('order_id.state', 'in', state), ('vendor_id', '=', rec_vendor_id), - ('id', '!=', order_line.id) + ('id', '!=', order_line.id), + ('order_id.date_order', '>=', delta_time) ], limit=1, order='create_date desc') + if rec_purchase_price != last_so.purchase_price: rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) if rec_taxes.price_include: - selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) + selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin_without_deduction / 100)) else: - selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) + selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin_without_deduction / 100)) tax_id = last_so.tax_id for tax in tax_id: if tax.price_include: @@ -881,12 +902,13 @@ class SaleOrder(models.Model): selling_price = order_line.price_unit tax_id = order_line.tax_id discount = order_line.discount + elif rec_vendor_id == order_line.vendor_id.id and rec_purchase_price != last_so.purchase_price: rec_taxes = self.env['account.tax'].search([('id', '=', rec_taxes_id)], limit=1) if rec_taxes.price_include: - selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin / 100)) + selling_price = (rec_purchase_price / 1.11) / (1 - (last_so.item_percent_margin_without_deduction / 100)) else: - selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin / 100)) + selling_price = rec_purchase_price / (1 - (last_so.item_percent_margin_without_deduction / 100)) tax_id = last_so.tax_id for tax in tax_id: if tax.price_include: @@ -894,10 +916,12 @@ class SaleOrder(models.Model): else: selling_price = selling_price discount = 0 + elif last_so: selling_price = last_so.price_unit tax_id = last_so.tax_id discount = last_so.discount + else: selling_price = order_line.price_unit tax_id = order_line.tax_id @@ -905,3 +929,4 @@ class SaleOrder(models.Model): order_line.price_unit = selling_price order_line.tax_id = tax_id order_line.discount = discount + order_line.order_id.use_button = True -- cgit v1.2.3