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') 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') 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') 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') 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') 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') 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') 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') 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 --- .../models/account_move_due_extension.py | 1 + indoteknik_custom/views/account_move_views.xml | 98 ++++++++++++---------- 2 files changed, 56 insertions(+), 43 deletions(-) (limited to 'indoteknik_custom') 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") diff --git a/indoteknik_custom/views/account_move_views.xml b/indoteknik_custom/views/account_move_views.xml index fee94b42..5df638bf 100644 --- a/indoteknik_custom/views/account_move_views.xml +++ b/indoteknik_custom/views/account_move_views.xml @@ -33,54 +33,66 @@ - - due.extension.form - due.extension - -
-
-
- - + /> +