From 2fec90b4a9040cde79774f61e4e19fff30f2a916 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 15:50:30 +0700 Subject: add some field in recommendation solr --- indoteknik_custom/models/solr/apache_solr.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 397db53b..7fc9dd5f 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -294,23 +294,23 @@ class ApacheSolr(models.Model): return False def _solr_sync_recommendation(self, limit=100): - solr_model = self.env['apache.solr'] variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) - # documents = [] + counter = 0 for variant in variants: - # document = solr_model.get_doc('recommendation', variant.id) + template_time = time.time() + counter += 1 document = {} document.update({ - 'id': variant.id, - 'display_name_s': variant.display_name, - 'name_s': variant.name, + 'id': variant.id or 0, + 'display_name_s': variant.display_name or '', + 'name_s': variant.name or '', 'default_code_s': variant.default_code or '', - 'product_rating_f': variant.product_tmpl_id.virtual_rating, - 'template_id_i': variant.product_tmpl_id.id, - 'active_s': variant.active, + 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, + 'template_id_i': variant.product_tmpl_id.id or 0, + 'active_s': str(variant.active) or 'false', + 'type_s': variant.product_tmpl_id.type or '' }) - # self.solr().add(docs=[document], softCommit=True) - # documents.append(document) variant.solr_flag = 1 _recommendation_solr.add(document) - # _recommendation_solr.add(documents) + _logger.info('[SYNC_VARIANTS_TO_SOLR] {}/{} {:.6f}'.format(counter, limit, time.time() - template_time)) + _logger.info('[SYNC_VARIANTS_TO_SOLR] Success add to solr variants %s' % variant.id) -- cgit v1.2.3 From 938ebeb3e785da9d0f40504932ae574d5f8eb27c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:07:00 +0700 Subject: add try catch while sync solr recommendation --- indoteknik_custom/models/solr/apache_solr.py | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 7fc9dd5f..2e275698 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -295,22 +295,21 @@ class ApacheSolr(models.Model): def _solr_sync_recommendation(self, limit=100): variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) - counter = 0 for variant in variants: - template_time = time.time() - counter += 1 - document = {} - document.update({ - 'id': variant.id or 0, - 'display_name_s': variant.display_name or '', - 'name_s': variant.name or '', - 'default_code_s': variant.default_code or '', - 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, - 'template_id_i': variant.product_tmpl_id.id or 0, - 'active_s': str(variant.active) or 'false', - 'type_s': variant.product_tmpl_id.type or '' - }) - variant.solr_flag = 1 - _recommendation_solr.add(document) - _logger.info('[SYNC_VARIANTS_TO_SOLR] {}/{} {:.6f}'.format(counter, limit, time.time() - template_time)) - _logger.info('[SYNC_VARIANTS_TO_SOLR] Success add to solr variants %s' % variant.id) + if variant.product_tmpl_id: # Check if product_tmpl_id exists + try: + document = { + 'id': variant.id or 0, + 'display_name_s': variant.display_name or '', + 'name_s': variant.name or '', + 'default_code_s': variant.default_code or '', + 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, + 'template_id_i': variant.product_tmpl_id.id or 0, + 'active_s': str(variant.active) or 'false', + 'type_s': variant.product_tmpl_id.type or '' + } + variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly + _recommendation_solr.add(document) + except Exception as e: + _logger.error("Failed to add document to Solr: %s", e) + _logger.debug("Document data: %s", document) -- cgit v1.2.3 From 4349b52b8221276a19104a21b2c2cd057e7ee725 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:15:10 +0700 Subject: try to fix error --- indoteknik_custom/models/solr/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 2e275698..3d6eeeca 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -305,11 +305,11 @@ class ApacheSolr(models.Model): 'default_code_s': variant.default_code or '', 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, 'template_id_i': variant.product_tmpl_id.id or 0, - 'active_s': str(variant.active) or 'false', + 'active': variant.active, 'type_s': variant.product_tmpl_id.type or '' } variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly _recommendation_solr.add(document) except Exception as e: _logger.error("Failed to add document to Solr: %s", e) - _logger.debug("Document data: %s", document) + _logger.error("Document data: %s", document) -- cgit v1.2.3 From acca01df9c8f8ac22551d02d80d93dd00362f993 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:17:38 +0700 Subject: bf --- indoteknik_custom/models/solr/apache_solr.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 3d6eeeca..d25b5fd6 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -295,6 +295,7 @@ class ApacheSolr(models.Model): def _solr_sync_recommendation(self, limit=100): variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) + document = {} for variant in variants: if variant.product_tmpl_id: # Check if product_tmpl_id exists try: -- cgit v1.2.3 From 2ca257f21bd5087604e3d0110eff16e40b0d8f83 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:27:52 +0700 Subject: bf --- indoteknik_custom/models/solr/apache_solr.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index d25b5fd6..0b1bd821 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -295,6 +295,7 @@ class ApacheSolr(models.Model): def _solr_sync_recommendation(self, limit=100): variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) + documents = [] document = {} for variant in variants: if variant.product_tmpl_id: # Check if product_tmpl_id exists @@ -310,7 +311,9 @@ class ApacheSolr(models.Model): 'type_s': variant.product_tmpl_id.type or '' } variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly - _recommendation_solr.add(document) + documents.append(document) except Exception as e: _logger.error("Failed to add document to Solr: %s", e) _logger.error("Document data: %s", document) + _recommendation_solr.add(documents) + return True -- cgit v1.2.3 From 4b75a370a2b16d21eeb3c71007885eae4dd4112c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:47:30 +0700 Subject: bf --- indoteknik_custom/models/solr/apache_solr.py | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 0b1bd821..1c4b7114 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -296,24 +296,24 @@ class ApacheSolr(models.Model): def _solr_sync_recommendation(self, limit=100): variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) documents = [] - document = {} + catch = {} for variant in variants: - if variant.product_tmpl_id: # Check if product_tmpl_id exists - try: - document = { - 'id': variant.id or 0, - 'display_name_s': variant.display_name or '', - 'name_s': variant.name or '', - 'default_code_s': variant.default_code or '', - 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, - 'template_id_i': variant.product_tmpl_id.id or 0, - 'active': variant.active, - 'type_s': variant.product_tmpl_id.type or '' - } - variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly - documents.append(document) - except Exception as e: - _logger.error("Failed to add document to Solr: %s", e) - _logger.error("Document data: %s", document) + try: + document = { + 'id': variant.id or 0, + 'display_name_s': variant.display_name or '', + 'name_s': variant.name or '', + 'default_code_s': variant.default_code or '', + 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, + 'template_id_i': variant.product_tmpl_id.id or 0, + 'active': variant.active or False, + 'type_s': variant.product_tmpl_id.type or '', + } + # variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly + documents.append(document) + catch = document + except Exception as e: + _logger.error("Failed to add document to Solr: %s", e) + _logger.error("Document data: %s", catch) _recommendation_solr.add(documents) return True -- cgit v1.2.3 From 20ae84eb89409a75b6ba024a9d9e06bdc593a480 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Jun 2024 16:51:40 +0700 Subject: bf --- indoteknik_custom/models/solr/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 1c4b7114..6560c9b5 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -306,10 +306,10 @@ class ApacheSolr(models.Model): 'default_code_s': variant.default_code or '', 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0, 'template_id_i': variant.product_tmpl_id.id or 0, - 'active': variant.active or False, + 'active_s': str(variant.active) or 'false', 'type_s': variant.product_tmpl_id.type or '', } - # variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly + variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly documents.append(document) catch = document except Exception as e: -- cgit v1.2.3 From a7eda38c3a1146a33da50ae6a6f87cbc61bbfc97 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Jun 2024 11:53:57 +0700 Subject: change request payment_schedule and fix sales order fulfilment bug --- indoteknik_custom/models/purchase_order.py | 102 +++++++++------------ .../models/report_stock_forecasted.py | 37 ++++---- 2 files changed, 65 insertions(+), 74 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 7b0fa20c..3a93c7db 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -61,6 +61,51 @@ class PurchaseOrder(models.Model): is_create_uangmuka = fields.Boolean(string='Uang Muka?') move_id = fields.Many2one('account.move', string='Account Move') + def _prepare_invoice(self): + """Prepare the dict of values to create the new invoice for a purchase order. + """ + self.ensure_one() + move_type = self._context.get('default_move_type', 'in_invoice') + journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal() + if not journal: + raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) + + + date_done = self.picking_ids[0].date_done + + day_extension = int(self.payment_term_id.line_ids.days) + payment_schedule = date_done + timedelta(days=day_extension) + # Menyesuaikan tanggal sesuai aturan yang diberikan + if payment_schedule.weekday() == 0: # 0 adalah indeks untuk hari Senin + payment_schedule -= timedelta(days=4) # Mundur ke hari Kamis + elif payment_schedule.weekday() == 2: # 2 adalah indeks untuk hari Rabu + payment_schedule -= timedelta(days=1) # Mundur ke hari Selasa + elif payment_schedule.weekday() == 4: # 4 adalah indeks untuk hari Jumat + payment_schedule -= timedelta(days=1) # Mundur ke hari Kamis + elif payment_schedule.weekday() == 5: # 5 adalah indeks untuk hari Sabtu + payment_schedule -= timedelta(days=2) # Mundur ke hari Kamis + elif payment_schedule.weekday() == 6: # 6 adalah indeks untuk hari Minggu + payment_schedule -= timedelta(days=3) # Mundur ke hari Kamis + + partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice'] + invoice_vals = { + 'ref': self.partner_ref or '', + 'move_type': move_type, + 'narration': self.notes, + 'currency_id': self.currency_id.id, + 'invoice_user_id': self.user_id and self.user_id.id or self.env.user.id, + 'partner_id': partner_invoice_id, + 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(partner_invoice_id)).id, + 'payment_reference': self.partner_ref or '', + 'partner_bank_id': self.partner_id.bank_ids[:1].id, + 'invoice_origin': self.name, + 'invoice_payment_term_id': self.payment_term_id.id, + 'invoice_line_ids': [], + 'company_id': self.company_id.id, + 'payment_schedule': payment_schedule + } + return invoice_vals + def _compute_matches_so(self): for po in self: matches = [] @@ -589,63 +634,6 @@ class PurchaseOrder(models.Model): self.total_so_margin = 0 self.total_so_percent_margin = 0 - # def compute_total_margin_from_apo(self): - # purchase_price_dict = {} - - - # for line in self.order_sales_match_line: - # for lines in self.order_line: - # product_id = lines.product_id.id - - # if product_id not in purchase_price_dict: - # purchase_price_dict[product_id] = lines.price_subtotal - - # sum_so_margin = sum_sales_price = sum_margin = 0 - # sale_order_line = line.sale_line_id - - # if not sale_order_line: - # sale_order_line = self.env['sale.order.line'].search([ - # ('product_id', '=', line.product_id.id), - # ('order_id', '=', line.sale_id.id) - # ], limit=1, order='price_reduce_taxexcl') - - # sum_so_margin += sale_order_line.item_margin - - # # sales_price = sale_order_line.price_reduce_taxexcl * line.qty_so - # sales_price = sale_order_line.price_reduce_taxexcl * lines.product_qty - - # if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': - # sales_price -= sale_order_line.delivery_amt_line - - # if sale_order_line.order_id.fee_third_party > 0: - # sales_price -= sale_order_line.fee_third_party_line - - # sum_sales_price += sales_price - - # product_id = sale_order_line.product_id.id - - # purchase_price = purchase_price_dict.get(product_id, 0) - # # purchase_price = lines.price_subtotal - # if lines.order_id.delivery_amount > 0: - # purchase_price += lines.delivery_amt_line - - # if line.purchase_order_id.delivery_amount > 0: - # purchase_price += line.delivery_amt_line - - # real_item_margin = sales_price - purchase_price - # sum_margin += real_item_margin - - # if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: - # self.total_so_margin = sum_so_margin - # self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 - # self.total_margin = sum_margin - # self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 - # else: - # self.total_margin = 0 - # self.total_percent_margin = 0 - # self.total_so_margin = 0 - # self.total_so_percent_margin = 0 - def compute_amt_total_without_service(self): for order in self: sum_price_total = 0 diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index 92da13d5..8e92a9b8 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -10,28 +10,31 @@ class ReplenishmentReport(models.AbstractModel): for line in lines: document_out = line.get('document_out') - order_id = document_out.id if document_out else None - product_id = line.get('product', {}).get('id') - query = [('product_id', '=', product_id)] - if order_id: - result = self._calculate_result(line) - quantity = line.get('quantity', 0) - result_dict.setdefault(order_id, []).append((result, quantity)) + if "SO/" in document_out.name: + document_out = line.get('document_out') + order_id = document_out.id if document_out else None + product_id = line.get('product', {}).get('id') + query = [('product_id', '=', product_id)] - for order_id, results in result_dict.items(): - sales_order = self.env['sale.order'].browse(order_id) + if order_id: + result = self._calculate_result(line) + quantity = line.get('quantity', 0) + result_dict.setdefault(order_id, []).append((result, quantity)) - for result, quantity in results: - self.env['sales.order.fullfillment'].create({ - 'sales_order_id': sales_order.id, - 'product_id': product_id, - 'reserved_from': result, - 'qty_fullfillment': quantity, - }) + for order_id, results in result_dict.items(): + sales_order = self.env['sale.order'].browse(order_id) + for result, quantity in results: + self.env['sales.order.fullfillment'].create({ + 'sales_order_id': sales_order.id, + 'product_id': product_id, + 'reserved_from': result, + 'qty_fullfillment': quantity, + }) - return lines + + return lines def _calculate_result(self, line): if line['document_in']: -- cgit v1.2.3 From 283f8f8153799adb2a635bf255b740c43f8d4381 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 19 Jun 2024 13:29:13 +0700 Subject: add invoice_id and partner_id on searching fiture due extension --- 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 cac73d07..c9af7f8d 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -14,6 +14,7 @@ class DueExtension(models.Model): number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True) partner_id = fields.Many2one('res.partner', string="Customer", readonly=True) order_id = fields.Many2one('sale.order', string="SO", readonly=True) + invoice_id = fields.Many2one('account.move', related='due_line.invoice_id', string='Invoice', readonly=False) due_line = fields.One2many('due.extension.line', 'due_id', string='Due Extension Lines', auto_join=True) old_due = fields.Date(string="Old Due") description = fields.Text(string="Description") -- cgit v1.2.3 From e819131a029681b10d5bafb2f4dc3948c429e776 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jun 2024 09:41:19 +0700 Subject: activate fullfilment on sale order --- indoteknik_custom/models/sale_order.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 91792b59..de61fb72 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -9,7 +9,7 @@ _logger = logging.getLogger(__name__) class SaleOrder(models.Model): _inherit = "sale.order" - # fullfillment_line = fields.One2many('sales.order.fullfillment', 'sales_order_id', string='Fullfillment') + fullfillment_line = fields.One2many('sales.order.fullfillment', 'sales_order_id', string='Fullfillment') order_sales_match_line = fields.One2many('sales.order.purchase.match', 'sales_order_id', string='Purchase Match Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True) total_margin = fields.Float('Total Margin', compute='_compute_total_margin', help="Total Margin in Sales Order Header") total_percent_margin = fields.Float('Total Percent Margin', compute='_compute_total_percent_margin', help="Total % Margin in Sales Order Header") @@ -96,16 +96,16 @@ class SaleOrder(models.Model): ('cust_director', 'Customer Director'), ('cust_procurement', 'Customer Procurement') ], string='Web Approval', copy=False) - # compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") + compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") - # def _compute_fullfillment(self): - # for rec in self: - # rec.fullfillment_line.unlink() + def _compute_fullfillment(self): + for rec in self: + rec.fullfillment_line.unlink() - # for line in rec.order_line: - # line._compute_reserved_from() + for line in rec.order_line: + line._compute_reserved_from() - # rec.compute_fullfillment = True + rec.compute_fullfillment = True def _compute_eta_date(self): max_leadtime = 0 -- cgit v1.2.3 From 5b3145bc1b56c423629f579e4eab8997e48cb1ad Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jun 2024 10:41:12 +0700 Subject: Fix bug fullfilment --- .../models/report_stock_forecasted.py | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index 8e92a9b8..d5e48fdc 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -11,9 +11,8 @@ class ReplenishmentReport(models.AbstractModel): for line in lines: document_out = line.get('document_out') - if "SO/" in document_out.name: - document_out = line.get('document_out') - order_id = document_out.id if document_out else None + if document_out and "SO/" in document_out.name: + order_id = document_out.id product_id = line.get('product', {}).get('id') query = [('product_id', '=', product_id)] @@ -22,17 +21,16 @@ class ReplenishmentReport(models.AbstractModel): quantity = line.get('quantity', 0) result_dict.setdefault(order_id, []).append((result, quantity)) - for order_id, results in result_dict.items(): - sales_order = self.env['sale.order'].browse(order_id) - - for result, quantity in results: - self.env['sales.order.fullfillment'].create({ - 'sales_order_id': sales_order.id, - 'product_id': product_id, - 'reserved_from': result, - 'qty_fullfillment': quantity, - }) + for order_id, results in result_dict.items(): + sales_order = self.env['sale.order'].browse(order_id) + for result, quantity in results: + self.env['sales.order.fullfillment'].create({ + 'sales_order_id': sales_order.id, + 'product_id': product_id, + 'reserved_from': result, + 'qty_fullfillment': quantity, + }) return lines -- cgit v1.2.3 From fe7087deb15d6dfa0d815c2e391cce9e753fd3cf Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 20 Jun 2024 13:52:27 +0700 Subject: fix purchase price logic in sale order --- indoteknik_custom/models/sale_order_line.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 509e3d1c..d362d573 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -110,9 +110,13 @@ class SaleOrderLine(models.Model): 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') + self.purchase_price = self._get_valid_purchase_price(purchase_price) else: - # purchase_price = self.env['purchase.pricelist'].search( - # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) 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') @@ -136,11 +140,15 @@ class SaleOrderLine(models.Model): 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( - [('product_id', '=', self.product_id.id)], limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') line.vendor_id = purchase_price.vendor_id line.tax_id = line.order_id.sales_tax_id - line.purchase_price = self._get_valid_purchase_price(purchase_price) + line.purchase_price = line._get_valid_purchase_price(purchase_price) line_name = ('[' + line.product_id.default_code + ']' if line.product_id.default_code else '') + ' ' + (line.product_id.name if line.product_id.name else '') + ' ' + \ ('(' + line.product_id.product_template_attribute_value_ids.name + ')' if line.product_id.product_template_attribute_value_ids.name else '') + ' ' + \ -- cgit v1.2.3 From 69679a78e128f22e0568c2b3e40b61f6065bf785 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jun 2024 17:01:32 +0700 Subject: fix error while create bill --- indoteknik_custom/models/purchase_order.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 3a93c7db..c2a599ca 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -69,9 +69,13 @@ class PurchaseOrder(models.Model): journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal() if not journal: raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) - - date_done = self.picking_ids[0].date_done + stock_picking = self.env['stock.picking'].search([ + ('purchase_id', '=', self.id), + ('state', '=', 'done') + ], order='date_done desc', limit=1) + + date_done = stock_picking.date_done day_extension = int(self.payment_term_id.line_ids.days) payment_schedule = date_done + timedelta(days=day_extension) -- cgit v1.2.3 From c3557f2c8b5837285558c8742aa0eb8bb6be1353 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 24 Jun 2024 10:05:58 +0700 Subject: change request alamat tempel --- indoteknik_custom/models/delivery_carrier.py | 1 + indoteknik_custom/models/sale_order.py | 1 + 2 files changed, 2 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/delivery_carrier.py b/indoteknik_custom/models/delivery_carrier.py index b3ae44e9..0bf1f08d 100644 --- a/indoteknik_custom/models/delivery_carrier.py +++ b/indoteknik_custom/models/delivery_carrier.py @@ -6,3 +6,4 @@ class DeliveryCarrier(models.Model): pic_name = fields.Char(string='PIC Name') pic_phone = fields.Char(string='PIC Phone') + address = fields.Char(string='Address') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index de61fb72..02ac4c5f 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -97,6 +97,7 @@ class SaleOrder(models.Model): ('cust_procurement', 'Customer Procurement') ], string='Web Approval', copy=False) compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") + note_ekspedisi = fields.Char(string="Note Ekspedisi") def _compute_fullfillment(self): for rec in self: -- cgit v1.2.3 From 6e256f5d35f48f75804829ddef08288905c33c68 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 24 Jun 2024 13:48:57 +0700 Subject: change request purchasing job --- indoteknik_custom/models/purchasing_job_multi_update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job_multi_update.py b/indoteknik_custom/models/purchasing_job_multi_update.py index deba960a..80a43e45 100644 --- a/indoteknik_custom/models/purchasing_job_multi_update.py +++ b/indoteknik_custom/models/purchasing_job_multi_update.py @@ -18,7 +18,7 @@ class PurchasingJobMultiUpdate(models.TransientModel): ('purchasing_job_id', '=', product.id) ]) - purchasing_job_state.unlink() + # purchasing_job_state.unlink() purchasing_job_state.create({ 'purchasing_job_id': product.id, -- cgit v1.2.3 From ac01fa257abf2f12588d240689c42f0d12da644f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 25 Jun 2024 09:09:34 +0700 Subject: trying to fix ppn keluar on bill --- indoteknik_custom/models/automatic_purchase.py | 12 +++++++----- indoteknik_custom/models/purchase_order.py | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 2c83c0ea..73416c48 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -506,13 +506,15 @@ class AutomaticPurchase(models.Model): taxes = '' human_last_update = purchase_price.human_last_update or datetime.min system_last_update = purchase_price.system_last_update or datetime.min - - price = purchase_price.product_price - taxes = purchase_price.taxes_product_id.id + + if purchase_price.taxes_product_id.type_tax_use == 'purchase': + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id.id if system_last_update > human_last_update: - price = purchase_price.system_price - taxes = purchase_price.taxes_system_id.id + if purchase_price.taxes_system_id.type_tax_use == 'purchase': + price = purchase_price.system_price + taxes = purchase_price.taxes_system_id.id return price, taxes diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index c2a599ca..836df945 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -79,17 +79,17 @@ class PurchaseOrder(models.Model): day_extension = int(self.payment_term_id.line_ids.days) payment_schedule = date_done + timedelta(days=day_extension) - # Menyesuaikan tanggal sesuai aturan yang diberikan - if payment_schedule.weekday() == 0: # 0 adalah indeks untuk hari Senin - payment_schedule -= timedelta(days=4) # Mundur ke hari Kamis - elif payment_schedule.weekday() == 2: # 2 adalah indeks untuk hari Rabu - payment_schedule -= timedelta(days=1) # Mundur ke hari Selasa - elif payment_schedule.weekday() == 4: # 4 adalah indeks untuk hari Jumat - payment_schedule -= timedelta(days=1) # Mundur ke hari Kamis - elif payment_schedule.weekday() == 5: # 5 adalah indeks untuk hari Sabtu - payment_schedule -= timedelta(days=2) # Mundur ke hari Kamis - elif payment_schedule.weekday() == 6: # 6 adalah indeks untuk hari Minggu - payment_schedule -= timedelta(days=3) # Mundur ke hari Kamis + + if payment_schedule.weekday() == 0: + payment_schedule -= timedelta(days=4) + elif payment_schedule.weekday() == 2: + payment_schedule -= timedelta(days=1) + elif payment_schedule.weekday() == 4: + payment_schedule -= timedelta(days=1) + elif payment_schedule.weekday() == 5: + payment_schedule -= timedelta(days=2) + elif payment_schedule.weekday() == 6: + payment_schedule -= timedelta(days=3) partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice'] invoice_vals = { -- cgit v1.2.3 From fcc629d93b0da863bcdab2fad0812deeee5da6b2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 26 Jun 2024 10:23:48 +0700 Subject: add tax validation & product category --- indoteknik_custom/models/manufacturing.py | 4 +++- indoteknik_custom/models/purchase_order.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/manufacturing.py b/indoteknik_custom/models/manufacturing.py index 2455a117..37c4e909 100644 --- a/indoteknik_custom/models/manufacturing.py +++ b/indoteknik_custom/models/manufacturing.py @@ -23,7 +23,9 @@ class Manufacturing(models.Model): def button_mark_done(self): if self._name != 'mrp.production': return super(Manufacturing, self).button_mark_done() - + # Check product category + if self.product_id.categ_id.name != 'Finish Good': + raise UserError('Tidak bisa di complete karna product category bukan Unit / Finish Good') for line in self.move_raw_ids: # if line.quantity_done > 0 and line.quantity_done != self.product_uom_qty: # raise UserError('Qty Consume per Line tidak sama dengan Qty to Produce') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 836df945..db474895 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -438,6 +438,12 @@ class PurchaseOrder(models.Model): for line in self.order_line: if not line.product_id.purchase_ok: raise UserError("Terdapat barang yang tidak bisa diproses") + # Validasi pajak + if not line.taxes_id: + raise UserError("Masukkan Tax untuk produk") + for tax in line.taxes_id: + if tax.type_tax_use != 'purchase': + raise UserError("Pastikan Tax Category nya adalah Purchase pada produk %s" % line.product_id.name) if line.price_unit != line.price_vendor and line.price_vendor != 0: self._send_po_not_sync() send_email = True -- cgit v1.2.3 From de28ec85c504b10098abdf53cfebebef68aaf626 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 26 Jun 2024 15:52:21 +0700 Subject: add alert if customer reference null --- indoteknik_custom/models/sale_order.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 02ac4c5f..efcbf606 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -454,6 +454,8 @@ 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 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") if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') @@ -484,6 +486,9 @@ class SaleOrder(models.Model): if FROM_WEBSITE and main_parent.use_so_approval and order.web_approval not in ['cust_procurement', 'cust_director']: raise UserError("This order not yet approved by customer procurement or director") + + 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") if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') -- cgit v1.2.3 From b74506f96049cbfd5ea475a12479e9d3a5337575 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 26 Jun 2024 16:30:57 +0700 Subject: send email faktur pajak --- indoteknik_custom/models/account_move.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 0ba25ad8..d81726e9 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -63,6 +63,38 @@ class AccountMove(models.Model): flag_delivery_amt = fields.Boolean(string="Flag Delivery Amount", compute='compute_flag_delivery_amt') nomor_kwitansi = fields.Char(string="Nomor Kwitansi") + @api.model + def generate_attachment(self, record): + # Fetch the binary field + # TODO nathan tolong rapihin + file_content = record.efaktur_document + file_name = "efaktur_document_{}.pdf".format(record.id) # Adjust the file extension if necessary + + attachment = self.env['ir.attachment'].create({ + 'name': file_name, + 'type': 'binary', + 'datas': file_content, + 'res_model': record._name, + 'res_id': record.id, + }) + return attachment + + @api.model + def send_scheduled_email(self): + # Get the records for which emails need to be sent + # records = self.search([]) # Adjust the domain as necessary + # TODO nathan tolong rapihin + records = self.env['account.move'].search([('id', '=', 194697)]) + # template = self.env.ref('my_module.email_template_example') + template = self.env['mail.template'].search([('id', '=', 8)]) + + for record in records: + attachment = self.generate_attachment(record) + email_values = { + 'attachment_ids': [(4, attachment.id)] + } + template.send_mail(record.id, email_values=email_values) + @api.model def create(self, vals): vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' -- cgit v1.2.3 From e33f2d321ee4db6a6e6a86e35243100b9f107f22 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:29:16 +0700 Subject: logbook bill & send email efaktur document --- indoteknik_custom/models/__init__.py | 2 + indoteknik_custom/models/account_move.py | 12 +-- indoteknik_custom/models/logbook_bill.py | 103 ++++++++++++++++++++++++ indoteknik_custom/models/purchase_order.py | 1 + indoteknik_custom/models/report_logbook_bill.py | 98 ++++++++++++++++++++++ 5 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 indoteknik_custom/models/logbook_bill.py create mode 100644 indoteknik_custom/models/report_logbook_bill.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index e6fefe2a..510b8b9d 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -117,3 +117,5 @@ from . import ged from . import account_move_multi_update_bills from . import def_cargo from . import purchase_order_multi_uangmuka2 +from . import logbook_bill +from . import report_logbook_bill diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index d81726e9..2996623c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -66,7 +66,6 @@ class AccountMove(models.Model): @api.model def generate_attachment(self, record): # Fetch the binary field - # TODO nathan tolong rapihin file_content = record.efaktur_document file_name = "efaktur_document_{}.pdf".format(record.id) # Adjust the file extension if necessary @@ -79,21 +78,18 @@ class AccountMove(models.Model): }) return attachment - @api.model + @api.constrains('efaktur_document') def send_scheduled_email(self): # Get the records for which emails need to be sent - # records = self.search([]) # Adjust the domain as necessary - # TODO nathan tolong rapihin - records = self.env['account.move'].search([('id', '=', 194697)]) - # template = self.env.ref('my_module.email_template_example') - template = self.env['mail.template'].search([('id', '=', 8)]) + records = self.search([('id', 'in', self.ids)]) + template = self.env.ref('indoteknik_custom.mail_template_efaktur_document') for record in records: attachment = self.generate_attachment(record) email_values = { 'attachment_ids': [(4, attachment.id)] } - template.send_mail(record.id, email_values=email_values) + template.send_mail(record.id, email_values=email_values, force_send=True) @api.model def create(self, vals): diff --git a/indoteknik_custom/models/logbook_bill.py b/indoteknik_custom/models/logbook_bill.py new file mode 100644 index 00000000..578ad59b --- /dev/null +++ b/indoteknik_custom/models/logbook_bill.py @@ -0,0 +1,103 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class LogbookBill(models.TransientModel): + _name = 'logbook.bill' + + name = fields.Char(string='Name', default='Logbook Bill') + logbook_bill_line = fields.One2many( + comodel_name='logbook.bill.line', + inverse_name='logbook_bill_id', + string='Logbook Bill Line' + ) + + + def grand_total(self, picking): + total = 0 + for line in picking.move_ids_without_package: + po = self.env['purchase.order.line'].search([ + ('order_id', '=', picking.purchase_id.id), + ('product_id', '=', line.product_id.id), + ], order='id desc', limit=1) + total += line.quantity_done * po.price_unit + return total + + def create_logbook_bill(self): + logbook_line = self.logbook_bill_line + + current_time = datetime.utcnow() + report_logbook_ids = [] + parameters_header = { + 'date': current_time, + 'created_by': self.env.user.id, + } + + report_logbook = self.env['report.logbook.bill'].create([parameters_header]) + for line in logbook_line: + picking = self.env['stock.picking'].search([('name', '=', line.name)], limit=1) + stock = picking + parent_id = stock.partner_id.parent_id.id + parent_id = parent_id if parent_id else stock.partner_id.id + + data = { + 'purchase_id': stock.purchase_id.id, + 'name': stock.name, + 'grand_total': self.grand_total(picking), + 'partner_id': parent_id, + 'invoice': line.invoice, + 'surat_jalan': line.surat_jalan, + 'proforma_invoice': line.proforma_invoice, + 'faktur_pajak': line.faktur_pajak, + 'date_approve': stock.date_done, + 'report_logbook_bill_id': report_logbook.id, + 'note': line.note, + 'note_finance': line.note_finance + } + self.env['report.logbook.bill.line'].create([data]) + + report_logbook_ids.append(report_logbook.id) + line.unlink() + + self.unlink() + return { + 'name': _('Report Logbook Bill'), + 'view_mode': 'tree,form', + 'res_model': 'report.logbook.bill', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', report_logbook_ids)], + } + +class LogbookBillLine(models.TransientModel): + _name = 'logbook.bill.line' + + name = fields.Char(string='Name') + logbook_bill_id = fields.Many2one('logbook.bill', string='Logbook Bill') + partner_id = fields.Many2one('res.partner', string='Customer') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + invoice = fields.Boolean(string='Invoice') + faktur_pajak = fields.Boolean(string='Faktur Pajak') + surat_jalan = fields.Boolean(string='Surat Jalan') + proforma_invoice = fields.Boolean(string='Proforma Invoice') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + note = fields.Char(string='Note Logistik') + note_finance = fields.Char(string='Note Finance') + + @api.onchange('name') + def onchange_name(self): + current_time = datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + + if self.name: + if len(self.name) == 13: + self.name = self.name[:-1] + picking = self.env['stock.picking'].search([('name', '=', self.name)], limit=1) + if picking: + self.partner_id = picking.partner_id + self.purchase_id = picking.purchase_id.id + + self.date_approve = picking.date_done + + else: + raise UserError('Nomor DO tidak ditemukan') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index db474895..6aec4074 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -60,6 +60,7 @@ class PurchaseOrder(models.Model): matches_so = fields.Many2many('sale.order', string='Matches SO', compute='_compute_matches_so') is_create_uangmuka = fields.Boolean(string='Uang Muka?') move_id = fields.Many2one('account.move', string='Account Move') + logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') def _prepare_invoice(self): """Prepare the dict of values to create the new invoice for a purchase order. diff --git a/indoteknik_custom/models/report_logbook_bill.py b/indoteknik_custom/models/report_logbook_bill.py new file mode 100644 index 00000000..9a7c1535 --- /dev/null +++ b/indoteknik_custom/models/report_logbook_bill.py @@ -0,0 +1,98 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +from pytz import timezone +from datetime import datetime + +class ReportLogbookBill(models.Model): + _name = 'report.logbook.bill' + _description = "Logbook Bill" + _inherit = ['mail.thread'] + _rec_name = 'name' + + name = fields.Char(string='Name', default='Logbook Bill') + date = fields.Datetime(string='Date Created') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + date_pengajuan = fields.Datetime(string='Date Pengajuan', tracking=3) + approve_by_finance = fields.Boolean(string='Approve By Finance', tracking=3) + pengajuan_by = fields.Many2one(comodel_name='res.users', string='Pengajuan By', tracking=3) + approve_by = fields.Many2one(comodel_name='res.users', string='Approve By', tracking=3) + created_by = fields.Many2one(comodel_name='res.users', string='Created By', tracking=3) + report_logbook_bill_line = fields.One2many( + comodel_name='report.logbook.bill.line', + inverse_name='report_logbook_bill_id', + string='Logbook Bill Line' + ) + state = fields.Selection( + [('belum_terima', 'Belum Terima'), + ('terima_sebagian', 'Terima Sebagian'), + ('terima_semua', 'Sudah di terima semua'), + ], + default='terima_semua', + string='Status', + tracking=True, + ) + + state_pengajuan = fields.Selection( + [('pengajuan', 'Pengajuan'), + ('diajukan', 'Sudah Diajukan'), + ], + default='pengajuan', + string='Status Pengajuan', + tracking=True, + ) + + count_line = fields.Char(string='Count Line', compute='_compute_count_line') + + @api.depends('report_logbook_bill_line') + def _compute_count_line(self): + for rec in self: + rec.count_line = len(rec.report_logbook_bill_line) + + @api.model + def create(self, vals): + vals['name'] = self.env['ir.sequence'].next_by_code('report.logbook.bill') or '0' + result = super(ReportLogbookBill, self).create(vals) + return result + + def approve(self): + current_time = datetime.utcnow() + if self.env.user.is_accounting: + self.approve_by_finance = True + self.date_approve = current_time + self.approve_by = self.env.user.id + if any(line.not_exist for line in self.report_logbook_bill_line): + if all(line.not_exist for line in self.report_logbook_bill_line): + self.state = 'belum_terima' + else: + self.state = 'terima_sebagian' + else: + self.state = 'terima_semua' + 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: + line.purchase_id.logbook_bill_id = self.id + +class ReportLogbookBillLine(models.Model): + _name = 'report.logbook.bill.line' + + name = fields.Char(string='Name') + logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + invoice = fields.Boolean(string='Invoice') + faktur_pajak = fields.Boolean(string='FP') + surat_jalan = fields.Boolean(string='SJ') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + partner_id = fields.Many2one('res.partner', string='Customer') + proforma_invoice = fields.Boolean(string='Proforma Inv') + report_logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') + not_exist = fields.Boolean(string='Not Exist') + date_approve = fields.Datetime(string='Date Approve', tracking=3) + grand_total = fields.Float(string='Grand Total') + note = fields.Char(string='Note Logistik') + note_finance = fields.Char(string='Note Finance') -- cgit v1.2.3 From 6b83f1e5a61c2d1f97fb5c0f1c55f0730f83a498 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:58:33 +0700 Subject: add flag if po has printed --- indoteknik_custom/models/purchase_order.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 6aec4074..4a029441 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -61,6 +61,10 @@ class PurchaseOrder(models.Model): is_create_uangmuka = fields.Boolean(string='Uang Muka?') move_id = fields.Many2one('account.move', string='Account Move') logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill') + status_printed = fields.Selection([ + ('not_printed', 'Belum Print'), + ('printed', 'Printed') + ], string='Printed?', copy=False, tracking=True) def _prepare_invoice(self): """Prepare the dict of values to create the new invoice for a purchase order. -- cgit v1.2.3 From 53e2b4ba69c7d0ea7a401ea6cc810dbcbf0fe46a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 28 Jun 2024 08:49:18 +0700 Subject: deactivate code send email efaktur document --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 2996623c..fbadd2aa 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -78,7 +78,7 @@ class AccountMove(models.Model): }) return attachment - @api.constrains('efaktur_document') + # @api.constrains('efaktur_document') def send_scheduled_email(self): # Get the records for which emails need to be sent records = self.search([('id', 'in', self.ids)]) -- cgit v1.2.3 From 0346d579b0db5969bf3a4e475cf8abb1b788cdd2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 28 Jun 2024 13:37:44 +0700 Subject: multi create uang muka penjualan --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_order.py | 7 ++ .../models/sale_order_multi_uangmuka_penjualan.py | 136 +++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 510b8b9d..ffd1b645 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -119,3 +119,4 @@ from . import def_cargo from . import purchase_order_multi_uangmuka2 from . import logbook_bill from . import report_logbook_bill +from . import sale_order_multi_uangmuka_penjualan diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index efcbf606..ce54bc74 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -99,6 +99,13 @@ class SaleOrder(models.Model): compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") note_ekspedisi = fields.Char(string="Note Ekspedisi") + def open_form_multi_create_uang_muka(self): + action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_sale_order_multi_uangmuka') + action['context'] = { + 'so_ids': [x.id for x in self] + } + return action + def _compute_fullfillment(self): for rec in self: rec.fullfillment_line.unlink() diff --git a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py new file mode 100644 index 00000000..bf717a4f --- /dev/null +++ b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py @@ -0,0 +1,136 @@ +from odoo import fields, models, _, api +from odoo.exceptions import UserError +from datetime import datetime +from odoo.http import request + +import logging, math + +_logger = logging.getLogger(__name__) + + +class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): + _name = 'sale.order.multi_uangmuka_penjualan' + _description = 'digunakan untuk membuat Uang Muka Penjualan' + + pay_amt = fields.Float(string='Uang Muka', help='berapa nilai yang terbentuk untuk COA Uang Muka Pembelian') + account_id = fields.Many2one('account.account', string='Bank Intransit', default=389, help='pilih COA intransit bank') + ongkir_amt = fields.Float(string='Ongkir', help='masukan nilai yang akan menjadi Pendapatan Ongkos Kirim') + selisih_amt = fields.Float(string='Selisih', help='masukan nilai yang akan menjadi Selisih Pembayaran') + total_amt = fields.Float(string='Total', help='Total yang akan masuk di journal entries') + + @api.onchange('pay_amt', 'ongkir_amt', 'selisih_amt') + def _compute_total_amt(self): + for o in self: + o.total_amt = o.pay_amt + o.ongkir_amt + o.selisih_amt + + def create_uangmukapenjualanselected(self): + so_ids = self._context['so_ids'] + orders = self.env['sale.order'].browse(so_ids) + po_is_uangmuka = self.env['sale.order'].search([ + ('id', 'in', [x.id for x in orders]) + ]) + + if not self.account_id: + raise UserError('Bank Intransit harus diisi') + if not self.env.user.has_group('account.group_account_manager'): + raise UserError('Hanya Finance yang dapat membuat Uang Muka penjualan') + + current_time = datetime.now() + + is_have_ongkir = is_have_selisih = False + if self.ongkir_amt > 0: + is_have_ongkir = True + if not math.isclose(self.selisih_amt, 0): + is_have_selisih = True + + partner_name = orders[0].partner_id.name + if orders[0].partner_id.parent_id: + partner_name = orders[0].partner_id.parent_id.name + + order_names = ', '.join([data.name for data in orders]) # Menggabungkan nama order menjadi satu string + ref_label = f'UANG MUKA penjualan {order_names} {partner_name}' + param_header = { + 'ref': ref_label, + 'date': current_time, + 'journal_id': 11, + # 'sale_id': order.id, + } + + account_move = self.env['account.move'].create([param_header]) + debit_entries = [] + pay_amt = 0 + + + for order in orders: + _logger.info('Success Create Uang Muka penjualan %s' % account_move.name) + partner_id = order.partner_id.parent_id.id if order.partner_id.parent_id else order.partner_id.id + partner = order.partner_id.parent_id.name if order.partner_id.parent_id else order.partner_id.name + + param_credit = { + 'move_id': account_move.id, + 'account_id': 449, # uang muka penjualan + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': order.amount_total, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_ongkir_credit = { + 'move_id': account_move.id, + 'account_id': 550, # pendapatan ongkos kirim + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.ongkir_amt, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + param_selisih_credit = { + 'move_id': account_move.id, + 'account_id': 561, # selisih pembayaran + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': 0, + 'credit': self.selisih_amt, + 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + } + + debit_entries.append(param_credit) + pay_amt += order.amount_total + + if is_have_ongkir: + debit_entries.append(param_ongkir_credit) + pay_amt += self.ongkir_amt + + if is_have_selisih: + debit_entries.append(param_selisih_credit) + pay_amt += self.selisih_amt + + param_debit = { + 'move_id': account_move.id, + 'account_id': self.account_id.id, # intransit + 'partner_id': partner_id, + 'currency_id': 12, + 'debit': pay_amt, + 'credit': 0, + 'name': ref_label, + } + + debit_entries.append(param_debit) + + # Create all account.move.line entries at once + self.env['account.move.line'].create(debit_entries) + + return { + 'name': _('Journal Entries'), + 'view_mode': 'form', + 'res_model': 'account.move', + 'target': 'current', + 'view_id': False, + 'type': 'ir.actions.act_window', + 'res_id': account_move.id + } + + # def save_multi_create_uang_muka(self): + + # account_move = self.create_uangmukapenjualanselected(purchase, is_create_uangmuka) + \ No newline at end of file -- cgit v1.2.3 From e50ec098e7eff86bfc372ffec74fffd5e4284770 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 28 Jun 2024 13:53:10 +0700 Subject: email notif to salesperson --- indoteknik_custom/models/sale_order.py | 78 +++++++++++++++++++++++++++++++--- 1 file changed, 73 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 ce54bc74..826315f2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2,6 +2,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import UserError, ValidationError from datetime import datetime, timedelta import logging, random, string, requests, math, json, re +from collections import defaultdict _logger = logging.getLogger(__name__) @@ -476,11 +477,75 @@ class SaleOrder(models.Model): raise UserError("Bisa langsung Confirm") - def send_notif_to_salesperson(self): - for rec in self: - if not rec.partner_id.main_parent_id.use_so_approval: continue - template = self.env.ref('indoteknik_custom.mail_template_sale_order_notification_to_salesperson') - template.send_mail(rec.id, force_send=True) + def send_notif_to_salesperson(self, cancel=False): + + if not cancel: + grouping_so = self.search([ + ('partner_id.parent_id.id', '=', self.partner_id.parent_id.id), + ('partner_id.site_id.id', '=', self.partner_id.site_id.id), + ]) + else: + grouping_so = self.search([ + ('partner_id.parent_id.id', '=', self.partner_id.parent_id.id), + ('partner_id.site_id.id', '=', self.partner_id.site_id.id), + ('id', '!=', self.id), + ]) + # Kelompokkan data berdasarkan salesperson + salesperson_data = {} + for rec in grouping_so: + if rec.user_id.id not in salesperson_data: + salesperson_data[rec.user_id.id] = {'name': rec.user_id.name, 'orders': [], 'total_amount': 0, 'sum_total_amount': 0, 'business_partner': '', 'site': ''} # Menetapkan nilai awal untuk 'site' + if rec.picking_ids: + if not any(picking.state in ['assigned', 'confirmed', 'waiting'] for picking in rec.picking_ids): + continue + if all(picking.state == 'done' for picking in rec.picking_ids): + continue + if all(picking.state == 'cancel' for picking in rec.picking_ids): + continue + if not rec.partner_id.main_parent_id.use_so_approval: + continue + order_total_amount = rec.amount_total # Mengakses langsung rec.amount_total + salesperson_data[rec.user_id.id]['orders'].append({ + 'order_name': rec.name, + 'parent_name': rec.partner_id.name, + 'site_name': rec.partner_id.site_id.name, + 'total_amount': rec.amount_total, + }) + salesperson_data[rec.user_id.id]['sum_total_amount'] += order_total_amount + salesperson_data[rec.user_id.id]['business_partner'] = grouping_so[0].partner_id.main_parent_id.name + salesperson_data[rec.user_id.id]['site'] = grouping_so[0].partner_id.site_id.name # Menambahkan nilai hanya jika ada + + # Kirim email untuk setiap salesperson + for salesperson_id, data in salesperson_data.items(): + if data['orders']: + # Buat isi tabel untuk email + table_content = '' + for order_data in data['orders']: + table_content += f""" + + {order_data['order_name']} + {order_data['parent_name']} + {order_data['site_name']} + {order_data['total_amount']} + + """ + + # Dapatkan email salesperson + salesperson_email = self.env['res.users'].browse(salesperson_id).partner_id.email + + # Kirim email hanya jika ada data yang dikumpulkan + template = self.env.ref('indoteknik_custom.mail_template_sale_order_notification_to_salesperson') + email_body = template.body_html.replace('${table_content}', table_content) + email_body = email_body.replace('${salesperson_name}', data['name']) + email_body = email_body.replace('${sum_total_amount}', str(data['sum_total_amount'])) + email_body = email_body.replace('${site}', str(data['site'])) + email_body = email_body.replace('${business_partner}', str(data['business_partner'])) + # Kirim email + self.env['mail.mail'].create({ + 'subject': 'Notification: Sale Orders', + 'body_html': email_body, + 'email_to': salesperson_email, + }).send() def action_confirm(self): for order in self: @@ -518,6 +583,7 @@ class SaleOrder(models.Model): def action_cancel(self): # TODO stephan prevent cancel if have invoice, do, and po + main_parent = self.partner_id.get_main_parent() if self._name != 'sale.order': return super(SaleOrder, self).action_cancel() @@ -533,6 +599,8 @@ class SaleOrder(models.Model): self.approval_status = False self.due_id = False + if main_parent.use_so_approval: + self.send_notif_to_salesperson(cancel=True) return super(SaleOrder, self).action_cancel() def validate_partner_invoice_due(self): -- cgit v1.2.3 From 53e3cacd7d32df44ce8637284c3ec16050e07e5b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 09:20:09 +0700 Subject: add flash sale to sales order --- indoteknik_custom/models/sale_order.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 826315f2..03b37229 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -72,6 +72,8 @@ class SaleOrder(models.Model): gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans') notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') + flash_sale = fields.Char(string='Flash Sale', help='data dari web') + flash_sale_icon = fields.Html(string='Flash Sale', compute='_compute_flash_sale_icon') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) @@ -99,7 +101,15 @@ class SaleOrder(models.Model): ], string='Web Approval', copy=False) compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") note_ekspedisi = fields.Char(string="Note Ekspedisi") - + + @api.depends('flash_sale') + def _compute_flash_sale_icon(self): + for order in self: + if order.flash_sale and order.flash_sale.lower() == 'true': + order.flash_sale_icon = '' + else: + order.flash_sale_icon = '' + def open_form_multi_create_uang_muka(self): action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_sale_order_multi_uangmuka') action['context'] = { -- cgit v1.2.3 From a54492e34db2a43d9aae2d575b2b3c073669631c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 11:19:19 +0700 Subject: update flash sale & get_request_params untuk boolean --- indoteknik_custom/models/sale_order.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 03b37229..6886f5a8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -72,8 +72,7 @@ class SaleOrder(models.Model): gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans') notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') - flash_sale = fields.Char(string='Flash Sale', help='data dari web') - flash_sale_icon = fields.Html(string='Flash Sale', compute='_compute_flash_sale_icon') + flash_sale = fields.Boolean(string='Flash Sale', help='Data dari web') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) @@ -102,14 +101,6 @@ class SaleOrder(models.Model): compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") note_ekspedisi = fields.Char(string="Note Ekspedisi") - @api.depends('flash_sale') - def _compute_flash_sale_icon(self): - for order in self: - if order.flash_sale and order.flash_sale.lower() == 'true': - order.flash_sale_icon = '' - else: - order.flash_sale_icon = '' - def open_form_multi_create_uang_muka(self): action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_sale_order_multi_uangmuka') action['context'] = { -- cgit v1.2.3 From 0c36919ea3a5e254f361002ddddb437a8c208eb9 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 15:39:35 +0700 Subject: move flash sale to other info --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6886f5a8..ac81737d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -72,7 +72,6 @@ class SaleOrder(models.Model): gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans') notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') - flash_sale = fields.Boolean(string='Flash Sale', help='Data dari web') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) @@ -92,6 +91,7 @@ class SaleOrder(models.Model): picking_iu_id = fields.Many2one('stock.picking', 'Picking IU') helper_by_id = fields.Many2one('res.users', 'Helper By') eta_date = fields.Datetime(string='ETA Date', copy=False, compute='_compute_eta_date') + flash_sale = fields.Boolean(string='Flash Sale', help='Data dari web') web_approval = fields.Selection([ ('company', 'Company'), ('cust_manager', 'Customer Manager'), -- cgit v1.2.3 From cc9c283c177b47567ef54284af0e18d02ca8b536 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 1 Jul 2024 15:41:39 +0700 Subject: fix duplikat data purchasing job --- indoteknik_custom/models/purchasing_job.py | 107 ++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 31 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 373e469a..27bb1f4e 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -44,21 +44,21 @@ class PurchasingJob(models.Model): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( - WITH latest_purchase_orders AS ( - SELECT - pol.product_id, - po.user_id, - ROW_NUMBER() OVER (PARTITION BY po.partner_id ORDER BY po.create_date DESC) AS order_rank - FROM purchase_order po - RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id - LEFT JOIN res_partner rp ON rp.id = po.partner_id - ), - random_user_ids AS ( - SELECT DISTINCT - CASE - WHEN vendor_id = 5571 THEN 27 - WHEN vendor_id = 9688 THEN 397 - WHEN vendor_id = 35475 THEN 397 + WITH latest_purchase_orders AS ( + SELECT + pol.product_id, + po.user_id, + ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank + FROM purchase_order po + RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id + LEFT JOIN res_partner rp ON rp.id = po.partner_id + ), + random_user_ids AS ( + SELECT DISTINCT + CASE + WHEN vendor_id = 5571 THEN 27 + WHEN vendor_id = 9688 THEN 397 + WHEN vendor_id = 35475 THEN 397 WHEN vendor_id = 29712 THEN 397 ELSE (CASE WHEN random() < 0.5 THEN 397 ELSE 1036 END) END AS user_id, @@ -70,11 +70,26 @@ class PurchasingJob(models.Model): LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id ) AS sub WHERE sub.vendor_id IS NOT NULL + ), + unique_sub AS ( + SELECT DISTINCT + vso.product_id, + sol.vendor_id + FROM v_sales_outstanding vso + LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id + WHERE sol.vendor_id IS NOT NULL + ), + latest_po_filtered AS ( + SELECT + product_id, + user_id + FROM latest_purchase_orders + WHERE order_rank = 1 ) SELECT pmp.product_id AS id, pmp.product_id, - sub.vendor_id, + MAX(sub.vendor_id) AS vendor_id, pmp.brand, pmp.item_code, pmp.product, @@ -84,29 +99,59 @@ class PurchasingJob(models.Model): pmp.action, MAX(pjs.status_apo) AS status_apo, MAX(pjs.note) AS note, - ru.user_id AS purchase_representative_id - FROM v_procurement_monitoring_by_product pmp - LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id - LEFT JOIN ( + MAX(ru.user_id) AS purchase_representative_id + FROM ( SELECT - vso.product_id, - sol.vendor_id - FROM v_sales_outstanding vso - LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id - ) AS sub ON sub.product_id = pmp.product_id - LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id + a.brand, + a.item_code, + a.product, + a.onhand, + a.incoming, + a.outgoing, + CASE + WHEN (a.incoming + a.onhand) < a.outgoing THEN 'kurang' + ELSE 'cukup' + END AS action, + a.onhand_as, + a.product_id, + a.po_number, + a.so_number + FROM ( + SELECT + xm.x_name AS brand, + COALESCE(pp.default_code, pt.default_code) AS item_code, + pt.name AS product, + get_qty_onhand(pp.id::numeric) AS onhand, + get_qty_incoming(pp.id::numeric) AS incoming, + get_qty_outgoing(pp.id::numeric) AS outgoing, + get_qty_onhand(pp.id::numeric, 75::numeric) AS onhand_as, + pp.id AS product_id, + COALESCE(get_incoming_number(pp.id::numeric), 'kosong') AS po_number, + COALESCE(get_outgoing_number(pp.id::numeric), 'kosong') AS so_number + FROM stock_move sm + JOIN stock_picking sp ON sp.id = sm.picking_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%' + AND sp.location_id IN (57, 83) + GROUP BY pp.id, xm.x_name, pp.default_code, pt.default_code, pt.name + ) a + ) pmp + LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id + LEFT JOIN unique_sub sub ON sub.product_id = pmp.product_id + LEFT JOIN latest_po_filtered 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' - AND sub.vendor_id IS NOT NULL + AND sub.vendor_id IS NOT NULL GROUP BY pmp.product_id, pmp.brand, pmp.item_code, pmp.product, - pmp.action, - sub.vendor_id, - ru.user_id - ) + pmp.action + ) """ % self._table) -- cgit v1.2.3 From fb0b0dfc765cff3377705e1d4904d3a6aa042872 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 1 Jul 2024 15:44:26 +0700 Subject: fix error purchasing job --- indoteknik_custom/models/purchasing_job.py | 34 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 27bb1f4e..230c171a 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -41,24 +41,23 @@ class PurchasingJob(models.Model): } def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( - WITH latest_purchase_orders AS ( - SELECT - pol.product_id, - po.user_id, - ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank - FROM purchase_order po - RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id - LEFT JOIN res_partner rp ON rp.id = po.partner_id - ), - random_user_ids AS ( - SELECT DISTINCT - CASE - WHEN vendor_id = 5571 THEN 27 - WHEN vendor_id = 9688 THEN 397 - WHEN vendor_id = 35475 THEN 397 + WITH latest_purchase_orders AS ( + SELECT + pol.product_id, + po.user_id, + ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank + FROM purchase_order po + RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id + LEFT JOIN res_partner rp ON rp.id = po.partner_id + ), + random_user_ids AS ( + SELECT DISTINCT + CASE + WHEN vendor_id = 5571 THEN 27 + WHEN vendor_id = 9688 THEN 397 + WHEN vendor_id = 35475 THEN 397 WHEN vendor_id = 29712 THEN 397 ELSE (CASE WHEN random() < 0.5 THEN 397 ELSE 1036 END) END AS user_id, @@ -151,8 +150,7 @@ class PurchasingJob(models.Model): pmp.item_code, pmp.product, pmp.action - ) - """ % self._table) + )""" % self._table) def open_form_multi_generate_request_po(self): -- cgit v1.2.3 From 773648e3e7d6464a96ef6dac10405926be0d0ad7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 1 Jul 2024 15:49:10 +0700 Subject: fix bug pj --- indoteknik_custom/models/purchasing_job.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 230c171a..4eaf700d 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -41,7 +41,7 @@ class PurchasingJob(models.Model): } def init(self): - self.env.cr.execute(""" + query = """ CREATE OR REPLACE VIEW %s AS ( WITH latest_purchase_orders AS ( SELECT @@ -150,7 +150,9 @@ class PurchasingJob(models.Model): pmp.item_code, pmp.product, pmp.action - )""" % self._table) + )""" % self._table + + self.env.cr.execute(query) def open_form_multi_generate_request_po(self): -- cgit v1.2.3 From e400125695357a2504041a678cccabb32c30f3af Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 1 Jul 2024 15:50:37 +0700 Subject: return code pj --- indoteknik_custom/models/purchasing_job.py | 85 +++++++----------------------- 1 file changed, 20 insertions(+), 65 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 4eaf700d..fb8dec3d 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -41,13 +41,14 @@ class PurchasingJob(models.Model): } def init(self): - query = """ + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( WITH latest_purchase_orders AS ( SELECT pol.product_id, po.user_id, - ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank + ROW_NUMBER() OVER (PARTITION BY po.partner_id ORDER BY po.create_date DESC) AS order_rank FROM purchase_order po RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id LEFT JOIN res_partner rp ON rp.id = po.partner_id @@ -69,26 +70,11 @@ class PurchasingJob(models.Model): LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id ) AS sub WHERE sub.vendor_id IS NOT NULL - ), - unique_sub AS ( - SELECT DISTINCT - vso.product_id, - sol.vendor_id - FROM v_sales_outstanding vso - LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id - WHERE sol.vendor_id IS NOT NULL - ), - latest_po_filtered AS ( - SELECT - product_id, - user_id - FROM latest_purchase_orders - WHERE order_rank = 1 ) SELECT pmp.product_id AS id, pmp.product_id, - MAX(sub.vendor_id) AS vendor_id, + sub.vendor_id, pmp.brand, pmp.item_code, pmp.product, @@ -98,61 +84,30 @@ class PurchasingJob(models.Model): pmp.action, MAX(pjs.status_apo) AS status_apo, MAX(pjs.note) AS note, - MAX(ru.user_id) AS purchase_representative_id - FROM ( - SELECT - a.brand, - a.item_code, - a.product, - a.onhand, - a.incoming, - a.outgoing, - CASE - WHEN (a.incoming + a.onhand) < a.outgoing THEN 'kurang' - ELSE 'cukup' - END AS action, - a.onhand_as, - a.product_id, - a.po_number, - a.so_number - FROM ( - SELECT - xm.x_name AS brand, - COALESCE(pp.default_code, pt.default_code) AS item_code, - pt.name AS product, - get_qty_onhand(pp.id::numeric) AS onhand, - get_qty_incoming(pp.id::numeric) AS incoming, - get_qty_outgoing(pp.id::numeric) AS outgoing, - get_qty_onhand(pp.id::numeric, 75::numeric) AS onhand_as, - pp.id AS product_id, - COALESCE(get_incoming_number(pp.id::numeric), 'kosong') AS po_number, - COALESCE(get_outgoing_number(pp.id::numeric), 'kosong') AS so_number - FROM stock_move sm - JOIN stock_picking sp ON sp.id = sm.picking_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%' - AND sp.location_id IN (57, 83) - GROUP BY pp.id, xm.x_name, pp.default_code, pt.default_code, pt.name - ) a - ) pmp + ru.user_id AS purchase_representative_id + FROM v_procurement_monitoring_by_product pmp LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id - LEFT JOIN unique_sub sub ON sub.product_id = pmp.product_id - LEFT JOIN latest_po_filtered po ON po.product_id = pmp.product_id + LEFT JOIN ( + SELECT + vso.product_id, + sol.vendor_id + FROM v_sales_outstanding vso + LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id + ) 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' - AND sub.vendor_id IS NOT NULL + AND sub.vendor_id IS NOT NULL GROUP BY pmp.product_id, pmp.brand, pmp.item_code, pmp.product, - pmp.action - )""" % self._table - - self.env.cr.execute(query) + pmp.action, + sub.vendor_id, + ru.user_id + ) + """ % self._table) def open_form_multi_generate_request_po(self): -- cgit v1.2.3 From a8f3194552f980ba6201ee834a0d5582cb584262 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 1 Jul 2024 15:52:30 +0700 Subject: fix code --- 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 fb8dec3d..373e469a 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -107,7 +107,7 @@ class PurchasingJob(models.Model): sub.vendor_id, ru.user_id ) - """ % self._table) + """ % self._table) def open_form_multi_generate_request_po(self): -- cgit v1.2.3 From f9c5b3dffcd71bfa9dea74c946d7b4277db66bd6 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 2 Jul 2024 09:25:31 +0700 Subject: fix bug on multi create uang muka penjualan and fix bug duplikat data purchasing job --- indoteknik_custom/models/purchasing_job.py | 45 +++++++++++++--------- .../models/sale_order_multi_uangmuka_penjualan.py | 10 ++--- 2 files changed, 31 insertions(+), 24 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 373e469a..40061d22 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -41,14 +41,13 @@ class PurchasingJob(models.Model): } def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) - self.env.cr.execute(""" + query = """ CREATE OR REPLACE VIEW %s AS ( WITH latest_purchase_orders AS ( SELECT pol.product_id, po.user_id, - ROW_NUMBER() OVER (PARTITION BY po.partner_id ORDER BY po.create_date DESC) AS order_rank + ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank FROM purchase_order po RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id LEFT JOIN res_partner rp ON rp.id = po.partner_id @@ -70,11 +69,26 @@ class PurchasingJob(models.Model): LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id ) AS sub WHERE sub.vendor_id IS NOT NULL + ), + unique_sub AS ( + SELECT DISTINCT + vso.product_id, + sol.vendor_id + FROM v_sales_outstanding vso + LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id + WHERE sol.vendor_id IS NOT NULL + ), + latest_po_filtered AS ( + SELECT + product_id, + user_id + FROM latest_purchase_orders + WHERE order_rank = 1 ) SELECT pmp.product_id AS id, pmp.product_id, - sub.vendor_id, + MAX(sub.vendor_id) AS vendor_id, pmp.brand, pmp.item_code, pmp.product, @@ -84,30 +98,23 @@ class PurchasingJob(models.Model): pmp.action, MAX(pjs.status_apo) AS status_apo, MAX(pjs.note) AS note, - ru.user_id AS purchase_representative_id + MAX(ru.user_id) AS purchase_representative_id FROM v_procurement_monitoring_by_product pmp LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id - LEFT JOIN ( - SELECT - vso.product_id, - sol.vendor_id - FROM v_sales_outstanding vso - LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id - ) AS sub ON sub.product_id = pmp.product_id - LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id + LEFT JOIN unique_sub sub ON sub.product_id = pmp.product_id + LEFT JOIN latest_po_filtered 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' - AND sub.vendor_id IS NOT NULL + AND sub.vendor_id IS NOT NULL GROUP BY pmp.product_id, pmp.brand, pmp.item_code, pmp.product, - pmp.action, - sub.vendor_id, - ru.user_id - ) - """ % self._table) + pmp.action + )""" % self._table + + self.env.cr.execute(query) def open_form_multi_generate_request_po(self): diff --git a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py index bf717a4f..f9120290 100644 --- a/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py +++ b/indoteknik_custom/models/sale_order_multi_uangmuka_penjualan.py @@ -48,7 +48,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): partner_name = orders[0].partner_id.parent_id.name order_names = ', '.join([data.name for data in orders]) # Menggabungkan nama order menjadi satu string - ref_label = f'UANG MUKA penjualan {order_names} {partner_name}' + ref_label = f'UANG MUKA PENJUALAN {order_names} {partner_name}' param_header = { 'ref': ref_label, 'date': current_time, @@ -62,7 +62,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): for order in orders: - _logger.info('Success Create Uang Muka penjualan %s' % account_move.name) + _logger.info('Success Create Uang Muka P %s' % account_move.name) partner_id = order.partner_id.parent_id.id if order.partner_id.parent_id else order.partner_id.id partner = order.partner_id.parent_id.name if order.partner_id.parent_id else order.partner_id.name @@ -73,7 +73,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): 'currency_id': 12, 'debit': 0, 'credit': order.amount_total, - 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + 'name': f'UANG MUKA PENJUALAN {order.name} {partner}', } param_ongkir_credit = { 'move_id': account_move.id, @@ -82,7 +82,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): 'currency_id': 12, 'debit': 0, 'credit': self.ongkir_amt, - 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + 'name': f'UANG MUKA PENJUALAN {order.name} {partner}', } param_selisih_credit = { 'move_id': account_move.id, @@ -91,7 +91,7 @@ class PurchaseOrderMultiUangmukaPenjualan(models.TransientModel): 'currency_id': 12, 'debit': 0, 'credit': self.selisih_amt, - 'name': f'UANG MUKA PEMBELIAN {order.name} {partner}', + 'name': f'UANG MUKA PENJUALAN {order.name} {partner}', } debit_entries.append(param_credit) -- cgit v1.2.3