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 ++++++++++ indoteknik_custom/models/sale_order_line.py | 106 +++++++++++++++++++++------- 2 files changed, 120 insertions(+), 25 deletions(-) (limited to 'indoteknik_custom/models') 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) diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 1f90b821..af3b4adc 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -40,8 +40,6 @@ class SaleOrderLine(models.Model): for match_so in matches_so: match_so.note_procurement = line.note_procurement - - @api.onchange('product_uom', 'product_uom_qty') def product_uom_change(self): @@ -63,9 +61,9 @@ class SaleOrderLine(models.Model): line.qty_reserved = reserved_qty def _compute_reserved_from(self): - for line in self: - report_stock_forecasted = self.env['report.stock.report_product_product_replenishment'] - report_stock_forecasted._get_report_data(False, [line.product_id.id]) + for line in self: + report_stock_forecasted = self.env['report.stock.report_product_product_replenishment'] + report_stock_forecasted._get_report_data(False, [line.product_id.id]) def _compute_vendor_subtotal(self): for line in self: @@ -105,59 +103,117 @@ class SaleOrderLine(models.Model): @api.onchange('vendor_id') def onchange_vendor_id(self): + # TODO : need to change this logic @stephan if not self.product_id or self.product_id.type == 'service': return elif self.product_id.categ_id.id == 34: # finish good / manufacturing only cost = self.product_id.standard_price self.purchase_price = cost elif self.product_id.x_manufacture.override_vendor_id: - purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), - ('product_id', '=', self.product_id.id)], - limit=1, order='count_trx_po desc, count_trx_po_vendor desc') - price, taxes = self._get_valid_purchase_price(purchase_price) + # purchase_price = self.env['purchase.pricelist'].search( + # [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), + # ('product_id', '=', self.product_id.id)], + # limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id) self.purchase_price = price self.purchase_tax_id = taxes + # else: + # purchase_price = self.env['purchase.pricelist'].search( + # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], + # limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + # price, taxes = self._get_valid_purchase_price(purchase_price) + # 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: - purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], - limit=1, order='count_trx_po desc, count_trx_po_vendor desc') - price, taxes = self._get_valid_purchase_price(purchase_price) - self.purchase_price = price - self.purchase_tax_id = taxes + 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 _get_purchase_price(self, product_id): + purchase_price = self.env['purchase.pricelist'].search( + [('product_id', '=', product_id.id), + ('is_winner', '=', True)], + limit=1) + + return self._get_valid_purchase_price(purchase_price) + + def _get_purchase_price_by_vendor(self, product_id, vendor_id): + purchase_price = self.env['purchase.pricelist'].search( + [('product_id', '=', product_id.id), + ('vendor_id', '=', vendor_id.id), + # ('is_winner', '=', True) + ], + limit=1) + + return self._get_valid_purchase_price(purchase_price) def _get_valid_purchase_price(self, purchase_price): 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': price = purchase_price.product_price taxes = purchase_price.taxes_product_id.id + vendor_id = purchase_price.vendor_id.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 - return price, taxes + return price, taxes, vendor_id @api.onchange('product_id') def product_id_change(self): + # TODO 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': - query = [('product_id', '=', line.product_id.id)] - if line.product_id.x_manufacture.override_vendor_id: - query = [('product_id', '=', line.product_id.id), - ('vendor_id', '=', line.product_id.x_manufacture.override_vendor_id.id)] - purchase_price = self.env['purchase.pricelist'].search( - query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') - line.vendor_id = purchase_price.vendor_id + # query = [('product_id', '=', line.product_id.id)] + # if line.product_id.x_manufacture.override_vendor_id: + # query = [('product_id', '=', line.product_id.id), + # ('vendor_id', '=', line.product_id.x_manufacture.override_vendor_id.id)] + # purchase_price = self.env['purchase.pricelist'].search( + # query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + price, taxes, vendor_id = self._get_purchase_price(line.product_id) + line.vendor_id = vendor_id line.tax_id = line.order_id.sales_tax_id - price, taxes = line._get_valid_purchase_price(purchase_price) + # price, taxes = line._get_valid_purchase_price(purchase_price) line.purchase_price = price + line.purchase_tax_id = taxes attribute_values = line.product_id.product_template_attribute_value_ids.mapped('name') attribute_values_str = ', '.join(attribute_values) if attribute_values else '' -- 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') 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') 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') 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') 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 d04f8c0c1496dc12e5b9c629be63ceead1d113a2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 12 Aug 2024 10:31:01 +0700 Subject: add 1 hari to day extension de --- indoteknik_custom/models/account_move_due_extension.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py index c9af7f8d..0399c6a2 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -24,6 +24,7 @@ class DueExtension(models.Model): ('approved', 'Approved'), ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) day_extension = fields.Selection([ + ('1', '1 Hari'), ('3', '3 Hari'), ('7', '7 Hari'), ('14', '14 Hari'), -- cgit v1.2.3 From 926b5bc3dbf88c4c92ed26c73e129a1c3896bde0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 12 Aug 2024 10:42:59 +0700 Subject: add npwp and sppkp validation --- indoteknik_custom/models/sale_order.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 44e4a886..14957b24 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -500,6 +500,10 @@ class SaleOrder(models.Model): raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") + if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.npwp != partner.npwp: + raise UserError("NPWP berbeda pada Master Data Customer") + if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.sppkp != partner.sppkp: + raise UserError("SPPKP berbeda pada Master Data Customer") if not order.client_order_ref and order.create_date > datetime(2024, 6, 27): raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO") @@ -517,6 +521,10 @@ class SaleOrder(models.Model): raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") + if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.npwp != partner.npwp: + raise UserError("NPWP berbeda pada Master Data Customer") + if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.sppkp != partner.sppkp: + raise UserError("SPPKP berbeda pada Master Data Customer") if not order.client_order_ref and order.create_date > datetime(2024, 6, 27): raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO") -- cgit v1.2.3 From 13e91e0f7d9132a3d6dfa53f898db2ca08ee089b Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 12 Aug 2024 15:42:20 +0700 Subject: add required --- indoteknik_custom/models/res_partner.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 77273610..39faf9d3 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -120,5 +120,10 @@ class ResPartner(models.Model): if self._name == 'res.partner': raise UserError('Maaf anda tidak bisa delete contact') + @api.onchange('customer_type') + def _onchange_customer_type(self): + if self.customer_type == 'nonpkp': + self.npwp = '00.000.000.0-000.000' + -- cgit v1.2.3 From 64b78ce44b4268abf406f1c6fbf8793a9499890b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 Aug 2024 09:01:54 +0700 Subject: update pj --- indoteknik_custom/models/purchasing_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 373e469a..da783ab1 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -96,7 +96,7 @@ class PurchasingJob(models.Model): ) AS sub ON sub.product_id = pmp.product_id LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id LEFT JOIN random_user_ids ru ON ru.vendor_id = sub.vendor_id OR (ru.vendor_id IS NULL AND sub.vendor_id != 9688) - WHERE pmp.action = 'kurang' + WHERE pmp.po_number = 'kosong' and pmp.action = 'kurang' AND sub.vendor_id IS NOT NULL GROUP BY pmp.product_id, -- cgit v1.2.3 From 433939b1a8b9cb6338b01282288704cf6f8430d3 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 Aug 2024 09:21:03 +0700 Subject: update purchasing job --- indoteknik_custom/models/automatic_purchase.py | 2 +- indoteknik_custom/models/purchasing_job.py | 33 +++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 73416c48..35dffc48 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -396,7 +396,7 @@ class AutomaticPurchase(models.Model): domain = [ ('product_id', '=', line.product_id.id) ] - sale = self.env['v.sales.outstanding'].search(domain, limit=1) + sale = self.env['v.sales.outstanding'].search(domain, order='create_date desc', limit=1) existing_match = self.env['automatic.purchase.sales.match'].search([ ('automatic_purchase_id', '=', self.id), diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index da783ab1..810a9e65 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -183,6 +183,7 @@ class OutstandingSales(models.Model): outgoing = fields.Float(string='Outgoing') brand = fields.Char(string='Brand') invoice_partner = fields.Char(string='Invoice Partner') + sale_order_create_date = fields.Datetime(string='Sale Order Create Date') def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -199,19 +200,23 @@ class OutstandingSales(models.Model): so.partner_invoice_id, sp.origin, rp2.name as salesperson, - coalesce(pp.default_code, pt.default_code) as item_code, pt.name as product, - sm.product_uom_qty as outgoing, xm.x_name as brand, rp.name as invoice_partner - from stock_move sm - join stock_picking sp on sp.id = sm.picking_id - join sale_order_line sol on sol.id = sm.sale_line_id - join sale_order so on so.id = sol.order_id - join res_partner rp on rp.id = so.partner_invoice_id - join res_users ru on ru.id = so.user_id - join res_partner rp2 on rp2.id = ru.partner_id - join product_product pp on pp.id = sm.product_id - join product_template pt on pt.id = pp.product_tmpl_id - left join x_manufactures xm on xm.id = pt.x_manufacture - where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') - and sp.name like '%OUT%' + coalesce(pp.default_code, pt.default_code) as item_code, + pt.name as product, + sm.product_uom_qty as outgoing, + xm.x_name as brand, + rp.name as invoice_partner, + so.create_date as sale_order_create_date + from stock_move sm + join stock_picking sp on sp.id = sm.picking_id + join sale_order_line sol on sol.id = sm.sale_line_id + join sale_order so on so.id = sol.order_id + join res_partner rp on rp.id = so.partner_invoice_id + join res_users ru on ru.id = so.user_id + join res_partner rp2 on rp2.id = ru.partner_id + join product_product pp on pp.id = sm.product_id + join product_template pt on pt.id = pp.product_tmpl_id + left join x_manufactures xm on xm.id = pt.x_manufacture + where sp.state in ('draft', 'waiting', 'confirmed', 'assigned') + and sp.name like '%OUT%' ) """) -- cgit v1.2.3 From 1fb90f4b0ea75ca0b9eb723924a2ba4ea27a5a65 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 Aug 2024 13:20:53 +0700 Subject: update pj --- indoteknik_custom/models/automatic_purchase.py | 2 +- indoteknik_custom/models/purchasing_job.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 35dffc48..f5b1baf9 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -396,7 +396,7 @@ class AutomaticPurchase(models.Model): domain = [ ('product_id', '=', line.product_id.id) ] - sale = self.env['v.sales.outstanding'].search(domain, order='create_date desc', limit=1) + sale = self.env['v.sales.outstanding'].search(domain, order='sale_order_create_date desc', limit=1) existing_match = self.env['automatic.purchase.sales.match'].search([ ('automatic_purchase_id', '=', self.id), diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 810a9e65..6e4f239d 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -96,7 +96,7 @@ class PurchasingJob(models.Model): ) AS sub ON sub.product_id = pmp.product_id LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id LEFT JOIN random_user_ids ru ON ru.vendor_id = sub.vendor_id OR (ru.vendor_id IS NULL AND sub.vendor_id != 9688) - WHERE pmp.po_number = 'kosong' and pmp.action = 'kurang' + WHERE pmp.action = 'kurang' AND sub.vendor_id IS NOT NULL GROUP BY pmp.product_id, -- cgit v1.2.3 From 7772fcd29c37b03ba0b23c233aa8e030a82a0d81 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 Aug 2024 14:08:29 +0700 Subject: approval date doc --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/approval_date_doc.py | 49 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 indoteknik_custom/models/approval_date_doc.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 116354d6..e9ce587c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -124,3 +124,4 @@ from . import report_logbook_bill from . import sale_order_multi_uangmuka_penjualan from . import shipment_group from . import sales_order_reject +from . import approval_date_doc diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py new file mode 100644 index 00000000..e00b7416 --- /dev/null +++ b/indoteknik_custom/models/approval_date_doc.py @@ -0,0 +1,49 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date, datetime +import logging + +_logger = logging.getLogger(__name__) + +class ApprovalDateDoc(models.Model): + _name = "approval.date.doc" + _description = "Approval Date Doc" + _rec_name = 'number' + + picking_id = fields.Many2one('stock.picking', string='Picking') + number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True) + driver_departure_date = fields.Datetime( + string='Driver Departure Date', + copy=False + ) + state = fields.Selection([('draft', 'Draft'), ('done', 'Done')], string='State', default='draft', tracking=True) + approve_date = fields.Datetime(string='Approve Date', copy=False) + approve_by = fields.Many2one('res.users', string='Approve By', copy=False) + sale_id = fields.Many2one('sale.order', string='Sale Order') + + @api.onchange('picking_id') + def onchange_picking_id(self): + if self.picking_id: + self.sale_id = self.picking_id.sale_id.id + + def check_invoice_so_picking(self): + for rec in self: + invoice = self.env['account.move'].search_count([('sale_id', '=', rec.picking_id.sale_id.id)]) + + if invoice < 1: + raise UserError("Sales Order Belum Memiliki Invoice, Anda Bisa Edit Di DO nya langsung") + + def button_approve(self): + if not self.env.user.is_accounting: + raise UserError("Hanya Accounting Yang Bisa Approve") + self.check_invoice_so_picking + self.picking_id.driver_departure_date = self.driver_departure_date + self.state = 'done' + self.approve_date = datetime.utcnow() + self.approve_by = self.env.user.id + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('approval.date.doc') or '0' + result = super(ApprovalDateDoc, self).create(vals) + return result -- cgit v1.2.3 From 8eaffe2f3590e52b90835fada67460e119032dee Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 13 Aug 2024 14:08:54 +0700 Subject: approval date doc --- indoteknik_custom/models/stock_picking.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index c151a543..47ac3166 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -26,7 +26,6 @@ class StockPicking(models.Model): # Delivery Order driver_departure_date = fields.Datetime( string='Driver Departure Date', - readonly=True, copy=False ) driver_arrival_date = fields.Datetime( @@ -91,6 +90,16 @@ class StockPicking(models.Model): date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) sale_order = fields.Char(string='Matches SO', copy=False) printed_sj = fields.Boolean('Printed Surat Jalan', help='flag which is internal use or not') + invoice_status = fields.Selection([ + ('upselling', 'Upselling Opportunity'), + ('invoiced', 'Fully Invoiced'), + ('to invoice', 'To Invoice'), + ('no', 'Nothing to Invoice') + ], string='Invoice Status', related="sale_id.invoice_status") + + @api.constrains('driver_departure_date') + def constrains_driver_departure_date(self): + self.date_doc_kirim = self.driver_departure_date def reset_status_printed(self): for rec in self: -- 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') 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 89f27a69415d8ffbadbfbab0e23af9cada86d163 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 13 Aug 2024 17:05:22 +0700 Subject: add api pickup-service --- indoteknik_custom/models/website_user_cart.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index dd3f87e6..10821cd3 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -24,16 +24,31 @@ class WebsiteUserCart(models.Model): def get_product(self): res = { - 'cart_id': self.id, - 'quantity': self.qty, + 'cart_id': self.id, + 'quantity': self.qty, 'selected': self.is_selected, 'can_buy': True } - + if self.product_id: res['cart_type'] = 'product' product = self.product_id.v2_api_single_response(self.product_id) res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) + + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 + flashsales = self.product_id._get_active_flash_sale() res['has_flashsale'] = True if len(flashsales) > 0 else False elif self.program_line_id: @@ -48,9 +63,9 @@ class WebsiteUserCart(models.Model): res['can_buy'] = False res['subtotal'] = self.qty * res['price']['price_discount'] - + return res - + def get_products(self): products = [x.get_product() for x in self] -- cgit v1.2.3 From 844cfbdf7a961dddb8c6c0b63f1dcaf72bc84f51 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 14 Aug 2024 09:44:48 +0700 Subject: arrival_time do --- indoteknik_custom/models/stock_picking.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 47ac3166..9fb4ae82 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -28,6 +28,10 @@ class StockPicking(models.Model): string='Driver Departure Date', copy=False ) + arrival_time = fields.Datetime( + string='Jam Kedatangan', + copy=False + ) driver_arrival_date = fields.Datetime( string='Driver Arrival Date', readonly=True, @@ -98,9 +102,14 @@ class StockPicking(models.Model): ], string='Invoice Status', related="sale_id.invoice_status") @api.constrains('driver_departure_date') - def constrains_driver_departure_date(self): + def constrains_driver_departure_date(self): self.date_doc_kirim = self.driver_departure_date + @api.constrains('arrival_time') + def constrains_arrival_time(self): + if self.arrival_time > datetime.datetime.utcnow(): + raise UserError('Jam kedatangan harus kurang dari Effective Date') + def reset_status_printed(self): for rec in self: rec.status_printed = 'not_printed' @@ -350,6 +359,9 @@ class StockPicking(models.Model): if not self.picking_code: self.picking_code = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0' + if not self.arrival_time: + raise UserError('Jam Kedatangan harus diisi') + if self.picking_type_id.code == 'incoming' and self.group_id.id == False and self.is_internal_use == False: raise UserError(_('Tidak bisa Validate jika tidak dari Document SO / PO')) @@ -381,6 +393,7 @@ class StockPicking(models.Model): res = super(StockPicking, self).button_validate() self.calculate_line_no() + self.date_done = datetime.datetime.utcnow() return res @api.model -- cgit v1.2.3 From c091a99de4e3c3bb4f85a8b0c91d75735ebefbd4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 14 Aug 2024 09:57:25 +0700 Subject: cr arrival time --- indoteknik_custom/models/stock_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 9fb4ae82..5029a770 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -359,7 +359,7 @@ class StockPicking(models.Model): if not self.picking_code: self.picking_code = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0' - if not self.arrival_time: + if not self.arrival_time and 'BU/IN/' in self.name: raise UserError('Jam Kedatangan harus diisi') if self.picking_type_id.code == 'incoming' and self.group_id.id == False and self.is_internal_use == False: -- 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') 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 0831a8dc838f7e6bcf184b3ba9e42fc45c3e4f20 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 14 Aug 2024 11:07:44 +0700 Subject: another checkpoint again --- indoteknik_custom/models/sale_order_line.py | 81 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'indoteknik_custom/models') 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': -- 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 ++++++++++++++++++++++------- indoteknik_custom/models/sale_order_line.py | 23 ++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) (limited to 'indoteknik_custom/models') 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 diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 52069d62..a64a744c 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -30,6 +30,7 @@ class SaleOrderLine(models.Model): amount_voucher_disc = fields.Float(string='Voucher Discount') qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') reserved_from = fields.Char(string='Reserved From', copy=False) + item_percent_margin_without_deduction = fields.Float('%Margin', compute='_compute_item_margin_without_deduction') @api.constrains('note_procurement') def note_procurement_to_apo(self): @@ -72,6 +73,28 @@ class SaleOrderLine(models.Model): else: line.vendor_subtotal = 0 + def _compute_item_margin_without_deduction(self): + for line in self: + if not line.product_id or line.product_id.type == 'service' \ + or line.price_unit <= 0 or line.product_uom_qty <= 0 \ + or not line.vendor_id: + line.item_percent_margin_without_deduction = 0 + continue + # calculate margin without tax + sales_price = line.price_reduce_taxexcl * line.product_uom_qty + + purchase_price = line.purchase_price + if line.purchase_tax_id.price_include: + purchase_price = line.purchase_price / 1.11 + + purchase_price = purchase_price * line.product_uom_qty + margin_per_item = sales_price - purchase_price + + if sales_price > 0: + line.item_percent_margin_without_deduction = round((margin_per_item / sales_price), 2) * 100 + else: + line.item_percent_margin_without_deduction = 0 + def compute_item_margin(self): for line in self: if not line.product_id or line.product_id.type == 'service' \ -- cgit v1.2.3 From 3c179deae0dbf618f6171003532dc86c48ada367 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 14 Aug 2024 13:36:51 +0700 Subject: cr logbook bill --- indoteknik_custom/models/report_logbook_bill.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/report_logbook_bill.py b/indoteknik_custom/models/report_logbook_bill.py index 9a7c1535..c78d558d 100644 --- a/indoteknik_custom/models/report_logbook_bill.py +++ b/indoteknik_custom/models/report_logbook_bill.py @@ -67,12 +67,13 @@ class ReportLogbookBill(models.Model): self.state = 'terima_sebagian' else: self.state = 'terima_semua' + self.relation_po_to_logbook() else: if self.env.user.is_logistic_approver: self.state_pengajuan = 'diajukan' self.date_pengajuan = current_time self.pengajuan_by = self.env.user.id - self.relation_po_to_logbook() + def relation_po_to_logbook(self): for line in self.report_logbook_bill_line: -- cgit v1.2.3 From 05fc26b12693250b29606e0eb7fc297f16716099 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 14 Aug 2024 14:59:47 +0700 Subject: add field on product --- indoteknik_custom/models/solr/product_template.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 892e7334..6ad49af7 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -68,7 +68,17 @@ class ProductTemplate(models.Model): # Mengumpulkan semua kategori category_ids = [category.id for category in template.public_categ_ids] category_names = [category.name for category in template.public_categ_ids] - + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', 'in', template.product_variant_ids.ids), + ('location_id', 'in', target_locations) + ]) + + is_in_bu = bool(stock_quant) + on_hand_qty = sum(stock_quant.mapped('quantity')) if stock_quant else 0 + document = solr_model.get_doc('product', template.id) document.update({ "id": template.id, @@ -99,6 +109,8 @@ class ProductTemplate(models.Model): 'sni_b': template.unpublished, 'tkdn_b': template.unpublished, "qty_sold_f": template.qty_sold, + "is_in_bu_b": is_in_bu, + "on_hand_qty_i": on_hand_qty, "voucher_pastihemat" : { "min_purchase" : voucher.min_purchase_amount or 0, "discount_type" : voucher.discount_type or '', -- cgit v1.2.3 From 8de88de447f441f129c44e9a0c6f57dd27d40512 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 14 Aug 2024 15:28:23 +0700 Subject: read only payment term --- indoteknik_custom/models/res_partner.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 39faf9d3..0b9a3a6c 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -51,9 +51,14 @@ class ResPartner(models.Model): def write(self, vals): res = super(ResPartner, self).write(vals) - if 'property_payment_term_id' in vals: - if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26: - raise UserError('Hanya Finance Accounting yang dapat merubah payment term') + # if 'property_payment_term_id' in vals: + # if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26: + # raise UserError('Hanya Finance Accounting yang dapat merubah payment term') + + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('You name it') return res -- cgit v1.2.3 From d4df708e5195e1c0c3b8e0ad90b7518e5d4d48c2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 14 Aug 2024 15:38:24 +0700 Subject: default payment term in sales --- indoteknik_custom/models/res_partner.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 0b9a3a6c..ac126337 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -48,6 +48,16 @@ class ResPartner(models.Model): user_payment_terms_purchase = fields.Many2one('res.users', string='Users Update Payment Terms') date_payment_terms_purchase = fields.Datetime(string='Date Update Payment Terms') + @api.model + def _default_payment_term(self): + return self.env.ref('__export__.account_payment_term_26_484409e2').id + + property_payment_term_id = fields.Many2one( + 'account.payment.term', + string='Payment Terms', + default=_default_payment_term + ) + def write(self, vals): res = super(ResPartner, self).write(vals) -- cgit v1.2.3