From 6b49797aca36574497f93a06f8e1c0622e5ad009 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 2 Nov 2023 15:40:43 +0700 Subject: add field kind of sparepart and accesories in product template --- indoteknik_custom/models/product_template.py | 4 ++++ indoteknik_custom/views/product_template.xml | 1 + 2 files changed, 5 insertions(+) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 10d109fb..d1de2221 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -53,6 +53,10 @@ class ProductTemplate(models.Model): seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') is_edited = fields.Boolean(string='Is Edited') qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') + kind_of = fields.Selection([ + ('sp', 'Spare Part'), + ('acc', 'Accessories') + ], string='Kind of', copy=False) def _get_qty_sold(self): for rec in self: diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 6fdb5e8f..92d2191e 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -10,6 +10,7 @@ + -- cgit v1.2.3 From a4cd5ce9cd8d5ef38062732a16a61d6d5c094e30 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 3 Nov 2023 10:46:02 +0700 Subject: initial commit for new window of customer commision --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/commision.py | 41 +++++++++++++ indoteknik_custom/security/ir.model.access.csv | 4 +- indoteknik_custom/views/customer_commision.xml | 82 ++++++++++++++++++++++++++ indoteknik_custom/views/ir_sequence.xml | 10 ++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/commision.py create mode 100644 indoteknik_custom/views/customer_commision.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 3bc4be60..a758d636 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -100,6 +100,7 @@ 'views/stock_move_line.xml', 'views/product_monitoring.xml', 'views/stock_warehouse_orderpoint.xml', + 'views/customer_commision.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 6a5eac00..e842b511 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -91,3 +91,4 @@ from . import sale_orders_multi_update from . import quotation_so_multi_update from . import product_monitoring from . import stock_warehouse_orderpoint +from . import commision diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py new file mode 100644 index 00000000..e39deb63 --- /dev/null +++ b/indoteknik_custom/models/commision.py @@ -0,0 +1,41 @@ +from odoo import models, api, fields +from odoo.exceptions import UserError +from datetime import datetime +import logging + +_logger = logging.getLogger(__name__) + + +class CustomerCommision(models.Model): + _name = 'customer.commision' + _order = 'id desc' + + number = fields.Char(string='Document No', index=True, copy=False, readonly=True) + date_from = fields.Date(string='Date From', required=True) + date_to = fields.Date(string='Date To', required=True) + partner_id = fields.Many2one('res.partner', String='Customer', required=True) + description = fields.Char(string='Description') + notification = fields.Char(string='Notification') + commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True) + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('customer.commision') or '0' + result = super(CustomerCommision, self).create(vals) + return result + + def generate_customer_commision(self): + print("masuk") + return + +class CustomerCommisionLine(models.Model): + _name = 'customer.commision.line' + _order = 'id' + + customer_commision_id = fields.Many2one('customer.commision', string='Ref', required=True, ondelete='cascade', copy=False) + invoice_id = fields.Many2one('account.move', string='Invoice') + partner_id = fields.Many2one('res.partner', string='Customer') + state = fields.Char(string='InvStatus') + dpp = fields.Float(string='DPP') + tax = fields.Float(string='TaxAmt') + total = fields.Float(string='Total') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 7a074c71..ed8d4725 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -78,4 +78,6 @@ access_stock_scheduler_compute,access.stock.scheduler.compute,model_stock_schedu access_sale_order_promotion,access.sale.order.promotion,model_sale_order_promotion,,1,1,1,1 access_sale_orders_multi_update,access.sale.orders.multi_update,model_sale_orders_multi_update,,1,1,1,1 access_quotation_so_multi_update,access.quotation.so.multi_update,model_quotation_so_multi_update,,1,1,1,1 -access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1 \ No newline at end of file +access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1 +access_customer_commision,access.customer.commision,model_customer_commision,,1,1,1,1 +access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml new file mode 100644 index 00000000..a714cb80 --- /dev/null +++ b/indoteknik_custom/views/customer_commision.xml @@ -0,0 +1,82 @@ + + + + customer.commision.tree + customer.commision + + + + + + + + + + + + + + customer.commision.line.tree + customer.commision.line + + + + + + + + + + + + + + customer_commision_form + customer.commision + +
+ +
+ + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + Customer Commision + ir.actions.act_window + customer.commision + tree,form + + + + \ No newline at end of file diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index 6798e5b4..86259b12 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -60,5 +60,15 @@ 1 1 + + + Customer Commision + customer.commision + TRUE + CC/%(year)s/ + 5 + 1 + 1 + \ No newline at end of file -- cgit v1.2.3 From e12706c91da229ee1f556635968f8d9c42555af1 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 3 Nov 2023 11:30:41 +0700 Subject: add button confirm --- indoteknik_custom/models/commision.py | 28 +++++++++++++++++++++++++- indoteknik_custom/views/customer_commision.xml | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index e39deb63..d6c0b0a5 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -24,8 +24,34 @@ class CustomerCommision(models.Model): result = super(CustomerCommision, self).create(vals) return result + def action_confirm_customer_commision(self): + print("a") + return + def generate_customer_commision(self): - print("masuk") + partners = [] + partners += self.partner_id.child_ids + partners.append(self.partner_id) + + for partner in partners: + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('partner_id.id', '=', partner.id), + ('invoice_date', '>=', self.date_from), + ('invoice_date', '<=', self.date_to), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + self.env['customer.commision.line'].create([{ + 'customer_commision_id': self.id, + 'partner_id': invoice.partner_id.id, + 'invoice_id': invoice.id, + 'state': invoice.state, + 'dpp': invoice.amount_untaxed_signed, + 'tax': invoice.amount_tax_signed, + 'total': invoice.amount_total_signed + }]) return class CustomerCommisionLine(models.Model): diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index a714cb80..b60cc1d9 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -35,6 +35,11 @@ customer.commision
+
+
-- cgit v1.2.3 From 566a20db595a2b0a1959a12d289361b16e1ef172 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 3 Nov 2023 13:42:51 +0700 Subject: add approval in editing reconcile & journal entries --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 3 ++- indoteknik_custom/models/account_bank_statement.py | 19 +++++++++++++ indoteknik_custom/models/account_move.py | 12 ++++++++- indoteknik_custom/models/users.py | 1 + indoteknik_custom/views/account_bank_statement.xml | 31 ++++++++++++++++++++++ indoteknik_custom/views/users.xml | 1 + 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 indoteknik_custom/models/account_bank_statement.py create mode 100644 indoteknik_custom/views/account_bank_statement.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 23abc084..b054d594 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -99,6 +99,7 @@ 'views/quotation_so_multi_update.xml', 'views/stock_move_line.xml', 'views/product_monitoring.xml', + 'views/account_bank_statement.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 1133c3e7..23a7331c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -89,4 +89,5 @@ from . import stock_scheduler_compute from . import promotion from . import sale_orders_multi_update from . import quotation_so_multi_update -from . import product_monitoring \ No newline at end of file +from . import product_monitoring +from . import account_bank_statement \ No newline at end of file diff --git a/indoteknik_custom/models/account_bank_statement.py b/indoteknik_custom/models/account_bank_statement.py new file mode 100644 index 00000000..495367e8 --- /dev/null +++ b/indoteknik_custom/models/account_bank_statement.py @@ -0,0 +1,19 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + + is_edit = fields.Boolean(string='Edit', default=False) + + def is_edited(self): + if not self.env.user.is_admin_reconcile: + raise UserError('Yang berhak hanya Mba Tania') + + self.is_edit = True + + def not_edited(self): + if not self.env.user.is_admin_reconcile: + raise UserError('Yang berhak hanya Mba Tania') + + self.is_edit = False \ No newline at end of file diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index a85e8caa..c55e2e1b 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -62,6 +62,10 @@ class AccountMove(models.Model): res = super(AccountMove, self).button_draft() if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa Reset to Draft') + + if self.write_date != self.create_date: + if self.statement_line_id and not self.statement_line_id.statement_id.is_edit and self.statement_line_id.statement_id.state == 'confirm': + raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') return res def action_post(self): @@ -145,4 +149,10 @@ class AccountMove(models.Model): 'move_ids': [x.id for x in self] } return action - \ No newline at end of file + + def write(self, vals): + res = super(AccountMove, self).write(vals) + if self.write_date != self.create_date: + if self.statement_line_id and not self.statement_line_id.statement_id.is_edit and self.statement_line_id.statement_id.state == 'confirm': + raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') + return res diff --git a/indoteknik_custom/models/users.py b/indoteknik_custom/models/users.py index b90c0097..2ff9933e 100644 --- a/indoteknik_custom/models/users.py +++ b/indoteknik_custom/models/users.py @@ -11,6 +11,7 @@ class Users(models.Model): is_accounting = fields.Boolean(string='Accounting', help='Berhak Approval Internal Use') is_logistic_approver = fields.Boolean(string='Logistic Approver', help='Berhak Approval Penerimaan Barang') is_editor_product = fields.Boolean(string='Editor Product', help='Berhak Mengedit Data Product') + is_admin_reconcile = fields.Boolean(string='Admin Reconcile', help='Berhak Mengedit Journal Reconcile') def notify_internal_users(self, message, title): users = self.search([('share', '=', False)]) diff --git a/indoteknik_custom/views/account_bank_statement.xml b/indoteknik_custom/views/account_bank_statement.xml new file mode 100644 index 00000000..a4e4f7e5 --- /dev/null +++ b/indoteknik_custom/views/account_bank_statement.xml @@ -0,0 +1,31 @@ + + + + + account.bank.statement.tree + account.bank.statement + + + + + + + + + + account.bank.statement.form + account.bank.statement + + + + + + + + + + \ No newline at end of file diff --git a/indoteknik_custom/views/users.xml b/indoteknik_custom/views/users.xml index d67b4474..020d8ddc 100644 --- a/indoteknik_custom/views/users.xml +++ b/indoteknik_custom/views/users.xml @@ -13,6 +13,7 @@ + -- cgit v1.2.3 From d05d1f609441ff0ead57d447c0ece63a968410de Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 4 Nov 2023 09:19:07 +0700 Subject: invisible field edit on reconcile --- indoteknik_custom/models/account_bank_statement.py | 6 +++--- indoteknik_custom/views/account_bank_statement.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/account_bank_statement.py b/indoteknik_custom/models/account_bank_statement.py index 495367e8..23008f13 100644 --- a/indoteknik_custom/models/account_bank_statement.py +++ b/indoteknik_custom/models/account_bank_statement.py @@ -4,16 +4,16 @@ from odoo.exceptions import AccessError, UserError, ValidationError class AccountBankStatement(models.Model): _inherit = "account.bank.statement" - is_edit = fields.Boolean(string='Edit', default=False) + is_edit = fields.Boolean(string='Unlock', default=False) def is_edited(self): if not self.env.user.is_admin_reconcile: - raise UserError('Yang berhak hanya Mba Tania') + raise UserError('Yang berhak hanya Mba Tania dan Iqmal Saputra') self.is_edit = True def not_edited(self): if not self.env.user.is_admin_reconcile: - raise UserError('Yang berhak hanya Mba Tania') + raise UserError('Yang berhak hanya Mba Tania dan Iqmal Saputra') self.is_edit = False \ No newline at end of file diff --git a/indoteknik_custom/views/account_bank_statement.xml b/indoteknik_custom/views/account_bank_statement.xml index a4e4f7e5..db380f37 100644 --- a/indoteknik_custom/views/account_bank_statement.xml +++ b/indoteknik_custom/views/account_bank_statement.xml @@ -23,7 +23,7 @@ - + -- cgit v1.2.3 From f8fcf079afbe107ed8bda3e6e832b58786d2a42a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 4 Nov 2023 11:53:45 +0700 Subject: fix error account move --- indoteknik_custom/models/account_move.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index c55e2e1b..ee4279b2 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -63,9 +63,10 @@ class AccountMove(models.Model): if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa Reset to Draft') - if self.write_date != self.create_date: - if self.statement_line_id and not self.statement_line_id.statement_id.is_edit and self.statement_line_id.statement_id.state == 'confirm': - raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') + for rec in self: + if rec.write_date != rec.create_date: + if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': + raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') return res def action_post(self): @@ -152,7 +153,8 @@ class AccountMove(models.Model): def write(self, vals): res = super(AccountMove, self).write(vals) - if self.write_date != self.create_date: - if self.statement_line_id and not self.statement_line_id.statement_id.is_edit and self.statement_line_id.statement_id.state == 'confirm': - raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') + for rec in self: + if rec.write_date != rec.create_date: + if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': + raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') return res -- cgit v1.2.3 From d445d93ab8688cd63a49ac6c128dca8eccb30fde Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 4 Nov 2023 11:56:57 +0700 Subject: change to dpp --- indoteknik_custom/models/commision.py | 43 +++++++++++++++++++++++++- indoteknik_custom/views/customer_commision.xml | 22 +++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index d6c0b0a5..315e47f6 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__) class CustomerCommision(models.Model): _name = 'customer.commision' _order = 'id desc' + _inherit = ['mail.thread'] + _rec_name = 'number' number = fields.Char(string='Document No', index=True, copy=False, readonly=True) date_from = fields.Date(string='Date From', required=True) @@ -17,6 +19,30 @@ class CustomerCommision(models.Model): description = fields.Char(string='Description') notification = fields.Char(string='Notification') commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True) + status = fields.Selection([ + ('pengajuan', 'Menunggu Approval'), + ('approved', 'Approved') + ], string='Status', copy=False, readonly=True, tracking=3) + commision_percent = fields.Float(string='Commision %', tracking=3) + commision_amt = fields.Float(string='Commision Amount', tracking=3) + total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp') + + @api.constrains('commision_percent') + def _onchange_commision_percent(self): + print('masuk onchange commision percent') + self.commision_amt = self.commision_percent * self.total_dpp // 100 + + # @api.constrains('commision_amt') + # def _onchange_commision_amt(self): + # print('masuk onchange commision amt') + # self.commision_percent = (self.commision_amt / self.grand_total * 100) + + def _compute_total_dpp(self): + for data in self: + total_dpp = 0 + for line in data.commision_lines: + total_dpp = total_dpp + line.dpp + data.total_dpp = total_dpp @api.model def create(self, vals): @@ -25,10 +51,20 @@ class CustomerCommision(models.Model): return result def action_confirm_customer_commision(self): - print("a") + if not self.status: + self.status = 'pengajuan' + elif self.status == 'pengajuan' and self.env.user.is_leader: + for line in self.commision_lines: + line.invoice_id.is_customer_commision = True + self.status = 'approved' + else: + raise UserError('Harus di approved oleh Pimpinan') return def generate_customer_commision(self): + if self.commision_lines: + raise UserError('Line sudah ada, tidak bisa di generate ulang') + partners = [] partners += self.partner_id.child_ids partners.append(self.partner_id) @@ -37,6 +73,7 @@ class CustomerCommision(models.Model): where = [ ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), + ('is_customer_commision', '=', False), ('partner_id.id', '=', partner.id), ('invoice_date', '>=', self.date_from), ('invoice_date', '<=', self.date_to), @@ -65,3 +102,7 @@ class CustomerCommisionLine(models.Model): dpp = fields.Float(string='DPP') tax = fields.Float(string='TaxAmt') total = fields.Float(string='Total') + +class AccountMove(models.Model): + _inherit = 'account.move' + is_customer_commision = fields.Boolean(string='Customer Commision Used') diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index b60cc1d9..ccaa0727 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -11,6 +11,7 @@ + @@ -46,10 +47,10 @@ - - + +
@@ -59,6 +60,10 @@ class="mr-2 oe_highlight" />
+ + + +
@@ -67,6 +72,10 @@ +
+ + +
@@ -78,10 +87,17 @@ tree,form - + + \ No newline at end of file -- cgit v1.2.3 From efa51f6b1c5254996db90a90468241da303a7e21 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 6 Nov 2023 08:40:38 +0700 Subject: new table of partner commision --- indoteknik_custom/models/commision.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 315e47f6..6d61de4c 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -6,6 +6,17 @@ import logging _logger = logging.getLogger(__name__) +class CustomerRebate(models.Model): + _name = 'customer.rebate' + _order = 'id desc' + _inherit = ['mail.thread'] + + partner_id = fields.Many2one('res.partner', string='Customer') + date_from = fields.Date(string='Date From', required=True) + date_to = fields.Date(string='Date To', required=True) + target_quarter = fields.Float(string='Target/Quarter') + + class CustomerCommision(models.Model): _name = 'customer.commision' _order = 'id desc' @@ -26,6 +37,14 @@ class CustomerCommision(models.Model): commision_percent = fields.Float(string='Commision %', tracking=3) commision_amt = fields.Float(string='Commision Amount', tracking=3) total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp') + commision_type = fields.Selection([ + ('fee', 'Fee'), + ('cashback', 'Cashback'), + ('rebate', 'Rebate'), + ], string='Commision Type') + + # add status for type of commision, fee, rebate / cashback + # include child or not? @api.constrains('commision_percent') def _onchange_commision_percent(self): -- cgit v1.2.3 From 7fccc21783e9c3b61c62757b202bccf3b40aba31 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 6 Nov 2023 13:11:47 +0700 Subject: get valid purchase price while create po from automatic purchase --- indoteknik_custom/models/automatic_purchase.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index f81ecdcc..502761e0 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -105,15 +105,18 @@ class AutomaticPurchase(models.Model): ('product_id', '=', point.product_id.id), # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), ('vendor_id', '=', self.vendor_id.id) - ], order='product_price asc', limit=1) + ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) else: purchase_price = self.env['purchase.pricelist'].search([ ('product_id', '=', point.product_id.id), # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), - ], order='product_price asc', limit=1) + ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) vendor_id = purchase_price.vendor_id.id - price = purchase_price.product_price or 0 + price = self._get_valid_purchase_price(purchase_price) + + if self.vendor_id and self.vendor_id.id != vendor_id: + continue self.env['automatic.purchase.line'].create([{ 'automatic_purchase_id': self.id, @@ -135,6 +138,19 @@ class AutomaticPurchase(models.Model): _logger.info('Create Automatic Purchase Line %s' % point.product_id.name) self.notification = "Automatic PO Created %s Lines" % count + def _get_valid_purchase_price(self, purchase_price): + p_price = 0 + if purchase_price.system_price > 0 and purchase_price.product_price > 0: + if purchase_price.human_last_update > purchase_price.system_last_update: + p_price = purchase_price.product_price + else: + p_price = purchase_price.system_price + elif purchase_price.system_price > 0 and purchase_price.product_price == 0: + p_price = purchase_price.system_price + elif purchase_price.system_price == 0 and purchase_price.product_price > 0: + p_price = purchase_price.product_price + return p_price + class AutomaticPurchaseLine(models.Model): _name = 'automatic.purchase.line' -- cgit v1.2.3 From 12492662cac198463233dec43952e43038611ada Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 8 Nov 2023 08:59:13 +0700 Subject: add list customer rebate --- indoteknik_custom/models/commision.py | 104 ++++++++++++++++++++++++- indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/customer_commision.xml | 84 ++++++++++++++++++++ 3 files changed, 186 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 6d61de4c..0dbbce52 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -11,10 +11,106 @@ class CustomerRebate(models.Model): _order = 'id desc' _inherit = ['mail.thread'] - partner_id = fields.Many2one('res.partner', string='Customer') - date_from = fields.Date(string='Date From', required=True) - date_to = fields.Date(string='Date To', required=True) - target_quarter = fields.Float(string='Target/Quarter') + partner_id = fields.Many2one('res.partner', string='Customer', required=True) + date_from = fields.Date(string='Date From', required=True, help="Pastikan tanggal 1 januari, jika tidak, code akan break") + date_to = fields.Date(string='Date To', required=True, help="Pastikan tanggal 31 desember, jika tidak, code akan break") + description = fields.Char(string='Description') + target_1st = fields.Float(string='Target/Quarter 1st') + target_2nd = fields.Float(string='Target/Quarter 2nd') + achieve_1 = fields.Float(string='Achieve 1 %') + achieve_2 = fields.Float(string='Achieve 2 %') + dpp_q1 = fields.Float(string='DPP Q1', compute='_compute_current_dpp') + dpp_q2 = fields.Float(string='DPP Q2', compute='_compute_current_dpp') + dpp_q3 = fields.Float(string='DPP Q3', compute='_compute_current_dpp') + dpp_q4 = fields.Float(string='DPP Q4', compute='_compute_current_dpp') + status_q1 = fields.Char(string='Status Q1', compute='_compute_achievement') + status_q2 = fields.Char(string='Status Q2', compute='_compute_achievement') + status_q3 = fields.Char(string='Status Q3', compute='_compute_achievement') + status_q4 = fields.Char(string='Status Q4', compute='_compute_achievement') + + def _compute_current_dpp(self): + for line in self: + line.dpp_q1 = line._get_current_dpp_q1(line) + line.dpp_q2 = line._get_current_dpp_q2(line) + line.dpp_q3 = line._get_current_dpp_q3(line) + line.dpp_q4 = line._get_current_dpp_q4(line) + + def _compute_achievement(self): + for line in self: + line.status_q1 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q1) + line.status_q2 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q2) + line.status_q3 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q3) + line.status_q4 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q4) + + def _check_achievement(self, target_1st, target_2nd, dpp): + status = 'not achieve' + if dpp >= target_1st: + status = '1st' + elif dpp >= target_2nd: + status = '2nd' + else: + status = 'not achieve' + return status + + def _get_current_dpp_q1(self, line): + sum_dpp = 0 + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('is_customer_commision', '=', False), + ('partner_id.id', '=', line.partner_id.id), + ('invoice_date', '>=', line.date_from), + ('invoice_date', '<=', '2023-03-31'), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + sum_dpp += invoice.amount_untaxed_signed + return sum_dpp + + def _get_current_dpp_q2(self, line): + sum_dpp = 0 + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('is_customer_commision', '=', False), + ('partner_id.id', '=', line.partner_id.id), + ('invoice_date', '>=', '2023-04-01'), + ('invoice_date', '<=', '2023-06-30'), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + sum_dpp += invoice.amount_untaxed_signed + return sum_dpp + + def _get_current_dpp_q3(self, line): + sum_dpp = 0 + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('is_customer_commision', '=', False), + ('partner_id.id', '=', line.partner_id.id), + ('invoice_date', '>=', '2023-07-01'), + ('invoice_date', '<=', '2023-09-30'), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + sum_dpp += invoice.amount_untaxed_signed + return sum_dpp + + def _get_current_dpp_q4(self, line): + sum_dpp = 0 + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('is_customer_commision', '=', False), + ('partner_id.id', '=', line.partner_id.id), + ('invoice_date', '>=', '2023-10-01'), + ('invoice_date', '<=', line.date_to), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + sum_dpp += invoice.amount_untaxed_signed + return sum_dpp class CustomerCommision(models.Model): diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index ed8d4725..ff467204 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -80,4 +80,5 @@ access_sale_orders_multi_update,access.sale.orders.multi_update,model_sale_order access_quotation_so_multi_update,access.quotation.so.multi_update,model_quotation_so_multi_update,,1,1,1,1 access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1 access_customer_commision,access.customer.commision,model_customer_commision,,1,1,1,1 -access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1 \ No newline at end of file +access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1 +access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index ccaa0727..f067093b 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -100,4 +100,88 @@ parent="sale.product_menu_catalog" sequence="101" /> + + + customer.rebate.tree + customer.rebate + + + + + + + + + + + + + + + + + + + + + + + + customer_rebate_form + customer.rebate + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + Customer Rebate + ir.actions.act_window + customer.rebate + tree,form + + + + + \ No newline at end of file -- cgit v1.2.3 From 23c357465171e83e716c7a2619d4aa03041705b8 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 8 Nov 2023 09:04:12 +0700 Subject: potential customer flag --- indoteknik_custom/models/res_partner.py | 1 + indoteknik_custom/views/res_partner.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 2983ca45..a1b57147 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -20,6 +20,7 @@ class ResPartner(models.Model): sppkp = fields.Char(string="SPPKP") counter = fields.Integer(string="Counter", default=0) digital_invoice_tax = fields.Boolean(string="Digital Invoice & Faktur Pajak") + is_potential = fields.Boolean(string='Potential') def get_child_ids(self): partner = self.env['res.partner'].search([('id', '=', self.id)], limit=1) diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index ef4898d0..c1ae3ed3 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -14,6 +14,7 @@ + -- cgit v1.2.3 From bdb068f9ac374b97504890c69308e6afd2c22527 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 8 Nov 2023 10:41:35 +0700 Subject: fix bug entries can edit after unlock reconcile --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index ee4279b2..2c9b9816 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -153,7 +153,7 @@ class AccountMove(models.Model): def write(self, vals): res = super(AccountMove, self).write(vals) - for rec in self: + for rec in self.line_ids: if rec.write_date != rec.create_date: if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') -- cgit v1.2.3 From f64c15810e963555e88511becee56f4ee8efb21b Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 8 Nov 2023 10:54:51 +0700 Subject: update commision for rebate --- indoteknik_custom/models/commision.py | 130 +++++++++++++++++-------- indoteknik_custom/views/customer_commision.xml | 6 +- 2 files changed, 95 insertions(+), 41 deletions(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 0dbbce52..f9edf2ad 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -28,6 +28,7 @@ class CustomerRebate(models.Model): status_q3 = fields.Char(string='Status Q3', compute='_compute_achievement') status_q4 = fields.Char(string='Status Q4', compute='_compute_achievement') + # all code class CustomerRebate deprecated, cause lack of performance def _compute_current_dpp(self): for line in self: line.dpp_q1 = line._get_current_dpp_q1(line) @@ -54,62 +55,70 @@ class CustomerRebate(models.Model): def _get_current_dpp_q1(self, line): sum_dpp = 0 + brand = [10, 89, 122] where = [ - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ('is_customer_commision', '=', False), - ('partner_id.id', '=', line.partner_id.id), - ('invoice_date', '>=', line.date_from), - ('invoice_date', '<=', '2023-03-31'), + ('move_id.move_type', '=', 'out_invoice'), + ('move_id.state', '=', 'posted'), + ('move_id.is_customer_commision', '=', False), + ('move_id.partner_id.id', '=', line.partner_id.id), + ('move_id.invoice_date', '>=', line.date_from), + ('move_id.invoice_date', '<=', '2023-03-31'), + ('product_id.x_manufacture', 'in', brand), ] - invoices = self.env['account.move'].search(where, order='id') - for invoice in invoices: - sum_dpp += invoice.amount_untaxed_signed + invoice_lines = self.env['account.move.line'].search(where, order='id') + for invoice_line in invoice_lines: + sum_dpp += invoice_line.price_subtotal return sum_dpp def _get_current_dpp_q2(self, line): sum_dpp = 0 + brand = [10, 89, 122] where = [ - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ('is_customer_commision', '=', False), - ('partner_id.id', '=', line.partner_id.id), - ('invoice_date', '>=', '2023-04-01'), - ('invoice_date', '<=', '2023-06-30'), + ('move_id.move_type', '=', 'out_invoice'), + ('move_id.state', '=', 'posted'), + ('move_id.is_customer_commision', '=', False), + ('move_id.partner_id.id', '=', line.partner_id.id), + ('move_id.invoice_date', '>=', '2023-04-01'), + ('move_id.invoice_date', '<=', '2023-06-30'), + ('product_id.x_manufacture', 'in', brand), ] - invoices = self.env['account.move'].search(where, order='id') + invoices = self.env['account.move.line'].search(where, order='id') for invoice in invoices: - sum_dpp += invoice.amount_untaxed_signed + sum_dpp += invoice.price_subtotal return sum_dpp def _get_current_dpp_q3(self, line): sum_dpp = 0 + brand = [10, 89, 122] where = [ - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ('is_customer_commision', '=', False), - ('partner_id.id', '=', line.partner_id.id), - ('invoice_date', '>=', '2023-07-01'), - ('invoice_date', '<=', '2023-09-30'), + ('move_id.move_type', '=', 'out_invoice'), + ('move_id.state', '=', 'posted'), + ('move_id.is_customer_commision', '=', False), + ('move_id.partner_id.id', '=', line.partner_id.id), + ('move_id.invoice_date', '>=', '2023-07-01'), + ('move_id.invoice_date', '<=', '2023-09-30'), + ('product_id.x_manufacture', 'in', brand), ] - invoices = self.env['account.move'].search(where, order='id') + invoices = self.env['account.move.line'].search(where, order='id') for invoice in invoices: - sum_dpp += invoice.amount_untaxed_signed + sum_dpp += invoice.price_subtotal return sum_dpp def _get_current_dpp_q4(self, line): sum_dpp = 0 + brand = [10, 89, 122] where = [ - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ('is_customer_commision', '=', False), - ('partner_id.id', '=', line.partner_id.id), - ('invoice_date', '>=', '2023-10-01'), - ('invoice_date', '<=', line.date_to), + ('move_id.move_type', '=', 'out_invoice'), + ('move_id.state', '=', 'posted'), + ('move_id.is_customer_commision', '=', False), + ('move_id.partner_id.id', '=', line.partner_id.id), + ('move_id.invoice_date', '>=', '2023-10-01'), + ('move_id.invoice_date', '<=', line.date_to), + ('product_id.x_manufacture', 'in', brand), ] - invoices = self.env['account.move'].search(where, order='id') + invoices = self.env['account.move.line'].search(where, order='id') for invoice in invoices: - sum_dpp += invoice.amount_untaxed_signed + sum_dpp += invoice.price_subtotal return sum_dpp @@ -127,7 +136,8 @@ class CustomerCommision(models.Model): notification = fields.Char(string='Notification') commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True) status = fields.Selection([ - ('pengajuan', 'Menunggu Approval'), + ('pengajuan1', 'Menunggu Approval Marketing'), + ('pengajuan2', 'Menunggu Approval Pimpinan'), ('approved', 'Approved') ], string='Status', copy=False, readonly=True, tracking=3) commision_percent = fields.Float(string='Commision %', tracking=3) @@ -137,7 +147,7 @@ class CustomerCommision(models.Model): ('fee', 'Fee'), ('cashback', 'Cashback'), ('rebate', 'Rebate'), - ], string='Commision Type') + ], string='Commision Type', required=True) # add status for type of commision, fee, rebate / cashback # include child or not? @@ -165,21 +175,61 @@ class CustomerCommision(models.Model): result = super(CustomerCommision, self).create(vals) return result - def action_confirm_customer_commision(self): + def action_confirm_customer_commision(self):#add 2 step approval if not self.status: - self.status = 'pengajuan' - elif self.status == 'pengajuan' and self.env.user.is_leader: + self.status = 'pengajuan1' + elif self.status == 'pengajuan1' and self.env.user.id == 19: + self.status = 'pengajuan2' + elif self.status == 'pengajuan2' and self.env.user.is_leader: for line in self.commision_lines: line.invoice_id.is_customer_commision = True self.status = 'approved' else: - raise UserError('Harus di approved oleh Pimpinan') + raise UserError('Harus di approved oleh yang bersangkutan') return def generate_customer_commision(self): if self.commision_lines: raise UserError('Line sudah ada, tidak bisa di generate ulang') + if self.commision_type == 'fee': + self._generate_customer_commision_fee() + else: + self._generate_customer_commision_rebate() + + def _generate_customer_commision_rebate(self): + partners = [] + partners += self.partner_id.child_ids + partners.append(self.partner_id) + + for partner in partners: + brand = [10, 89, 122] + where = [ + ('move_id.move_type', '=', 'out_invoice'), + ('move_id.state', '=', 'posted'), + ('move_id.is_customer_commision', '=', False), + ('move_id.amount_residual_signed', '=', 0), + ('move_id.partner_id.id', '=', partner.id), + ('move_id.invoice_date', '>=', self.date_from), + ('move_id.invoice_date', '<=', self.date_to), + ('product_id.x_manufacture', 'in', brand), + ] + invoice_lines = self.env['account.move.line'].search(where, order='id') + for invoice_line in invoice_lines: + tax = invoice_line.price_total - invoice_line.price_subtotal + self.env['customer.commision.line'].create([{ + 'customer_commision_id': self.id, + 'partner_id': invoice_line.move_id.partner_id.id, + 'invoice_id': invoice_line.move_id.id, + 'state': invoice_line.move_id.state, + 'product_id': invoice_line.product_id.id, + 'dpp': invoice_line.price_subtotal, + 'tax': tax, + 'total': invoice_line.price_total + }]) + return + + def _generate_customer_commision_fee(self): partners = [] partners += self.partner_id.child_ids partners.append(self.partner_id) @@ -189,6 +239,7 @@ class CustomerCommision(models.Model): ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), ('is_customer_commision', '=', False), + ('amount_residual_signed', '=', 0), ('partner_id.id', '=', partner.id), ('invoice_date', '>=', self.date_from), ('invoice_date', '<=', self.date_to), @@ -217,6 +268,7 @@ class CustomerCommisionLine(models.Model): dpp = fields.Float(string='DPP') tax = fields.Float(string='TaxAmt') total = fields.Float(string='Total') + product_id = fields.Many2one('product.product', string='Product') class AccountMove(models.Model): _inherit = 'account.move' diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index f067093b..e299d37e 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -24,9 +24,10 @@ + - - + + @@ -61,6 +62,7 @@ />
+ -- cgit v1.2.3 From 019493c8e0e6cc5aff4c612eb332f1c882b0519d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 8 Nov 2023 11:03:23 +0700 Subject: button reset to draft entries --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 2c9b9816..4e1beb3a 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -63,7 +63,7 @@ class AccountMove(models.Model): if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa Reset to Draft') - for rec in self: + for rec in self.line_ids: if rec.write_date != rec.create_date: if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') -- cgit v1.2.3 From db561aabfa404edfff9462c812d15a200223b978 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 8 Nov 2023 11:19:54 +0700 Subject: add responsible in po base on manufacture responsible --- indoteknik_custom/models/purchase_order.py | 9 +++++++++ indoteknik_custom/views/purchase_order.xml | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index f9cd7f5b..b0f1a569 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -49,6 +49,15 @@ class PurchaseOrder(models.Model): has_active_invoice = fields.Boolean(string='Has Active Invoice', compute='_compute_has_active_invoice') description = fields.Char(string='Description', help='bisa diisi sebagai informasi indent barang tertentu atau apapun') purchase_order_lines = fields.One2many('purchase.order.line', 'order_id', string='Indent', auto_join=True) + responsible_ids = fields.Many2many('res.users', string='Responsibles', compute='_compute_responsibles') + + def _compute_responsibles(self): + for purchase in self: + resposible_ids = [] + for line in purchase.order_line: + resposible_ids.append(line.product_id.x_manufacture.user_id.id) + resposible_ids = list(set(resposible_ids)) + purchase.responsible_ids = resposible_ids def _compute_has_active_invoice(self): for order in self: diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 8f7ea6df..bc84bcd1 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -79,7 +79,7 @@ - + @@ -115,6 +115,7 @@ +
@@ -130,6 +131,7 @@ + -- cgit v1.2.3 From 27b2145a60fde081f7dd5555126e169d426904e9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 9 Nov 2023 09:21:45 +0700 Subject: mandatory source in sale order --- indoteknik_custom/models/sale_order.py | 2 +- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cc6941a9..dbc4e863 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -77,7 +77,7 @@ class SaleOrder(models.Model): voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) amount_voucher_disc = fields.Float(string='Voucher Discount') - source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]") + source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True) estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0) email = fields.Char(string='Email') picking_iu_id = fields.Many2one('stock.picking', 'Picking IU') diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index a260c68a..c6187f60 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -50,7 +50,7 @@ - + -- cgit v1.2.3 From 14156f7d6f55eaa4e74310ee1aa4e5128aa17fff Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 9 Nov 2023 09:55:34 +0700 Subject: mandatory static npwp,sppkp,customer_type in sale order and fix log note journal entries --- indoteknik_custom/models/account_move.py | 18 ++++++++++++------ indoteknik_custom/models/sale_order.py | 6 +++--- indoteknik_custom/views/sale_order.xml | 6 +++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 4e1beb3a..fe9db583 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -151,10 +151,16 @@ class AccountMove(models.Model): } return action - def write(self, vals): - res = super(AccountMove, self).write(vals) + @api.constrains('efaktur_id', 'ref', 'date', 'journal_id', 'name') + def constrains_edit(self): for rec in self.line_ids: - if rec.write_date != rec.create_date: - if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': - raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') - return res + if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': + raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') + + # def write(self, vals): + # res = super(AccountMove, self).write(vals) + # for rec in self.line_ids: + # if rec.write_date != rec.create_date: + # if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': + # raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') + # return res diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index dbc4e863..f9229bca 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -70,9 +70,9 @@ class SaleOrder(models.Model): customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') - ]) - sppkp = fields.Char(string="SPPKP") - npwp = fields.Char(string="NPWP") + ], required=True) + sppkp = fields.Char(string="SPPKP", required=True) + npwp = fields.Char(string="NPWP", required=True) purchase_total = fields.Monetary(string='Purchase Total', compute='_compute_purchase_total') voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index c6187f60..5596c271 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -45,9 +45,9 @@ - - - + + + -- cgit v1.2.3 From a98d7f339c2bb15974f941b450cbaeb0de64283e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 10 Nov 2023 08:03:29 +0700 Subject: minor change requisition --- indoteknik_custom/models/requisition.py | 223 +++++++++++++++++--------------- indoteknik_custom/views/requisition.xml | 25 ++-- 2 files changed, 131 insertions(+), 117 deletions(-) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 19f0ba7e..6408c4fd 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__) class Requisition(models.Model): _name = 'requisition' _order = 'id desc' + _inherit = ['mail.thread'] + _rec_name = 'number' number = fields.Char(string='Document No', index=True, copy=False, readonly=True) date_doc = fields.Date(string='Date', help='isi tanggal hari ini') @@ -26,108 +28,108 @@ class Requisition(models.Model): result = super(Requisition, self).create(vals) return result - def create_requisition_from_sales_with_price(self): - if self.requisition_lines: - raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') - if not self.sale_order_id: - raise UserError('Sale Order harus diisi') - if self.is_po: - raise UserError('Sudah jadi PO, tidak bisa di create ulang PO nya') - - count = 0 - for order_line in self.sale_order_id.order_line: - # get purchase price altama, if nothing, then get other cheaper, if nothing then last po - purchase_price = order_line.purchase_price - vendor_id = order_line.vendor_id.id - - # get qty available bandengan - qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty - suggest = 'harus beli' - if qty_available > order_line.product_qty: - suggest = 'masih cukup' - - self.env['requisition.line'].create([{ - 'requisition_id': self.id, - 'partner_id': vendor_id, - 'brand_id': order_line.product_id.product_tmpl_id.x_manufacture.id, - 'product_id': order_line.product_id.id, - 'qty_purchase': order_line.product_uom_qty, - 'tax_id': order_line.purchase_tax_id.id, - 'price_unit': purchase_price, - 'subtotal': purchase_price * order_line.product_uom_qty, - 'source': 'sales', - 'qty_available_store': qty_available, - 'suggest': suggest, - }]) - count+=1 - _logger.info('Create Requisition %s' % order_line.product_id.name) - self.notification = "Requisition Created %s lines" % count - - def create_requisition_from_sales(self): - if self.requisition_lines: - raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') - if not self.sale_order_id: - raise UserError('Sale Order harus diisi') - if self.is_po: - raise UserError('Sudah jadi PO, tidak bisa di create ulang PO nya') + # def create_requisition_from_sales_with_price(self): + # if self.requisition_lines: + # raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') + # if not self.sale_order_id: + # raise UserError('Sale Order harus diisi') + # if self.is_po: + # raise UserError('Sudah jadi PO, tidak bisa di create ulang PO nya') + + # count = 0 + # for order_line in self.sale_order_id.order_line: + # # get purchase price altama, if nothing, then get other cheaper, if nothing then last po + # purchase_price = order_line.purchase_price + # vendor_id = order_line.vendor_id.id + + # # get qty available bandengan + # qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty + # suggest = 'harus beli' + # if qty_available > order_line.product_qty: + # suggest = 'masih cukup' + + # self.env['requisition.line'].create([{ + # 'requisition_id': self.id, + # 'partner_id': vendor_id, + # 'brand_id': order_line.product_id.product_tmpl_id.x_manufacture.id, + # 'product_id': order_line.product_id.id, + # 'qty_purchase': order_line.product_uom_qty, + # 'tax_id': order_line.purchase_tax_id.id, + # 'price_unit': purchase_price, + # 'subtotal': purchase_price * order_line.product_uom_qty, + # 'source': 'sales', + # 'qty_available_store': qty_available, + # 'suggest': suggest, + # }]) + # count+=1 + # _logger.info('Create Requisition %s' % order_line.product_id.name) + # self.notification = "Requisition Created %s lines" % count + + # def create_requisition_from_sales(self): + # if self.requisition_lines: + # raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') + # if not self.sale_order_id: + # raise UserError('Sale Order harus diisi') + # if self.is_po: + # raise UserError('Sudah jadi PO, tidak bisa di create ulang PO nya') - # old_requisition = self.env['requisition'].search([('sale_order_id', '=', self.sale_order_id.id)], limit=1) - # if old_requisition: - # raise UserError('Sudah pernah jadi Requisition') - - count = 0 - for order_line in self.sale_order_id.order_line: - # get purchase price altama, if nothing, then get other cheaper, if nothing then last po - purchase_price = 0 - vendor_id = 0 - - # get qty available bandengan - qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty - suggest = 'harus beli' - if qty_available > order_line.product_qty: - suggest = 'masih cukup' - - purchase_pricelist = self.env['purchase.pricelist'].search([ - ('product_id.id', '=', order_line.product_id.id), - ('vendor_id.id', '=', 5571) - ], order='product_price asc', limit=1) - purchase_price = purchase_pricelist.product_price - vendor_id = purchase_pricelist.vendor_id.id - source = 'PriceList' + # # old_requisition = self.env['requisition'].search([('sale_order_id', '=', self.sale_order_id.id)], limit=1) + # # if old_requisition: + # # raise UserError('Sudah pernah jadi Requisition') + + # count = 0 + # for order_line in self.sale_order_id.order_line: + # # get purchase price altama, if nothing, then get other cheaper, if nothing then last po + # purchase_price = 0 + # vendor_id = 0 + + # # get qty available bandengan + # qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty + # suggest = 'harus beli' + # if qty_available > order_line.product_qty: + # suggest = 'masih cukup' + + # purchase_pricelist = self.env['purchase.pricelist'].search([ + # ('product_id.id', '=', order_line.product_id.id), + # ('vendor_id.id', '=', 5571) + # ], order='product_price asc', limit=1) + # purchase_price = purchase_pricelist.product_price + # vendor_id = purchase_pricelist.vendor_id.id + # source = 'PriceList' - if not purchase_price or purchase_price <= 0: - purchase_pricelist = self.env['purchase.pricelist'].search([('product_id', '=', order_line.product_id.id)], order='product_price asc', limit=1) - purchase_price = purchase_pricelist.product_price - vendor_id = purchase_pricelist.vendor_id.id - source = 'PriceList' + # if not purchase_price or purchase_price <= 0: + # purchase_pricelist = self.env['purchase.pricelist'].search([('product_id', '=', order_line.product_id.id)], order='product_price asc', limit=1) + # purchase_price = purchase_pricelist.product_price + # vendor_id = purchase_pricelist.vendor_id.id + # source = 'PriceList' - if not purchase_price or purchase_price <= 0: - last_po_line = self.env['purchase.order.line'].search([('product_id', '=', order_line.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) - purchase_price = last_po_line.price_unit - vendor_id = last_po_line.order_id.partner_id.id - source = 'LastPO' + # if not purchase_price or purchase_price <= 0: + # last_po_line = self.env['purchase.order.line'].search([('product_id', '=', order_line.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) + # purchase_price = last_po_line.price_unit + # vendor_id = last_po_line.order_id.partner_id.id + # source = 'LastPO' - if not purchase_price or purchase_price <= 0: - purchase_price = 0 - vendor_id = 5571 - source = 'Nothing' - - self.env['requisition.line'].create([{ - 'requisition_id': self.id, - 'partner_id': vendor_id, - 'brand_id': order_line.product_id.product_tmpl_id.x_manufacture.id, - 'product_id': order_line.product_id.id, - 'qty_purchase': order_line.product_uom_qty, - 'tax_id': order_line.purchase_tax_id.id, - 'price_unit': purchase_price, - 'subtotal': purchase_price * order_line.product_uom_qty, - 'source': source, - 'qty_available_store': qty_available, - 'suggest': suggest, - }]) - count+=1 - _logger.info('Create Requisition %s' % order_line.product_id.name) - self.notification = "Requisition Created %s lines" % count + # if not purchase_price or purchase_price <= 0: + # purchase_price = 0 + # vendor_id = 5571 + # source = 'Nothing' + + # self.env['requisition.line'].create([{ + # 'requisition_id': self.id, + # 'partner_id': vendor_id, + # 'brand_id': order_line.product_id.product_tmpl_id.x_manufacture.id, + # 'product_id': order_line.product_id.id, + # 'qty_purchase': order_line.product_uom_qty, + # 'tax_id': order_line.purchase_tax_id.id, + # 'price_unit': purchase_price, + # 'subtotal': purchase_price * order_line.product_uom_qty, + # 'source': source, + # 'qty_available_store': qty_available, + # 'suggest': suggest, + # }]) + # count+=1 + # _logger.info('Create Requisition %s' % order_line.product_id.name) + # self.notification = "Requisition Created %s lines" % count def create_po_from_requisition(self): if not self.requisition_lines: @@ -141,13 +143,14 @@ class Requisition(models.Model): for vendor in vendor_ids: param_header = { 'partner_id': vendor['partner_id'][0], - 'partner_ref': self.sale_order_id.name, + # 'partner_ref': self.sale_order_id.name, 'currency_id': 12, 'user_id': self.env.user.id, 'company_id': 1, # indoteknik dotcom gemilang 'picking_type_id': 28, # indoteknik bandengan receipts 'date_order': current_time, - 'sale_order_id': self.sale_order_id.id + 'sale_order_id': self.sale_order_id.id, + 'note_description': 'from Purchase Requisition' } # new_po = self.env['purchase.order'].create([param_header]) products_vendors = self.env['requisition.line'].search([ @@ -156,9 +159,9 @@ class Requisition(models.Model): ('qty_purchase', '>', 0) ], order='brand_id') count = brand_id = 0 - new_po = '' + for product in products_vendors: - if not new_po or ((count == 200 or brand_id != product.brand_id.id) and vendor['partner_id'][0] == 5571): + if count == 200 or brand_id != product.brand_id.id: count = 0 counter_po_number += 1 new_po = self.env['purchase.order'].create([param_header]) @@ -178,14 +181,16 @@ class Requisition(models.Model): if qty_available > product.qty_purchase: suggest = 'masih cukup' + tax = [22] + param_line = { 'order_id': new_po.id, 'sequence': count, 'product_id': product.product_id.id, 'product_qty': product.qty_purchase, 'product_uom_qty': product.qty_purchase, - 'price_unit': product.last_price, - 'taxes_id': product.tax_id, + 'price_unit': product.price_unit, + 'taxes_id': tax, 'qty_available_store': qty_available, 'suggest': suggest, } @@ -193,7 +198,7 @@ class Requisition(models.Model): product.current_po_id = new_po.id product.current_po_line_id = new_line.id _logger.info('Create PO Line %s' % product.product_id.name) - self.notification = self.notification + ' %s' % new_po.name + # self.notification = self.notification + ' %s' % new_po.name self.is_po = True class RequisitionLine(models.Model): @@ -221,7 +226,13 @@ class RequisitionLine(models.Model): @api.onchange('price_unit') def _onchange_price_unit(self): - self.subtotal = self.price_unit * self.qty_purchase + for line in self: + line.subtotal = line.price_unit * line.qty_purchase + + @api.onchange('product_id') + def _onchange_product(self): + for line in self: + line.brand_id = line.product_id.product_tmpl_id.x_manufacture.id class RequisitionPurchaseMatch(models.Model): _name = 'requisition.purchase.match' diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml index e7335a57..e9c3b4e0 100644 --- a/indoteknik_custom/views/requisition.xml +++ b/indoteknik_custom/views/requisition.xml @@ -62,16 +62,6 @@
-