summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-11-08 10:54:51 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-11-08 10:54:51 +0700
commitf64c15810e963555e88511becee56f4ee8efb21b (patch)
treeb97add5f83d2e630cba192527c932b0ed1fe54ea
parente7b7ec12a2cde3720c0a56ba93588a9834d16458 (diff)
update commision for rebate
-rw-r--r--indoteknik_custom/models/commision.py130
-rw-r--r--indoteknik_custom/views/customer_commision.xml6
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 @@
<field name="partner_id" readonly="1"/>
<field name="invoice_id" readonly="1"/>
<field name="state" readonly="1"/>
+ <field name="product_id" readonly="1" optional="hide"/>
<field name="dpp" readonly="1"/>
- <field name="tax" readonly="1"/>
- <field name="total" readonly="1"/>
+ <field name="tax" readonly="1" optional="hide"/>
+ <field name="total" readonly="1" optional="hide"/>
</tree>
</field>
</record>
@@ -61,6 +62,7 @@
/>
</div>
<field name="date_to"/>
+ <field name="commision_type"/>
<field name="notification" readonly="1"/>
<field name="status" readonly="1"/>
<field name="total_dpp"/>