[IMP] commission_simple: add total base amount in view and XLSX report

This commit is contained in:
Alexis de Lattre
2025-09-05 09:29:00 +00:00
parent cfb1d2ce1e
commit 204df0e1e8
3 changed files with 17 additions and 8 deletions

View File

@@ -32,7 +32,10 @@ class CommissionResult(models.Model):
states={'done': [('readonly', True)]})
amount_total = fields.Monetary(
string='Commission Total', currency_field='company_currency_id',
compute='_compute_amount_total', store=True, tracking=True)
compute='_compute_totals', store=True, tracking=True)
base_total = fields.Monetary(
string="Commission Base Total", currency_field='company_currency_id',
compute='_compute_totals', store=True, tracking=True)
state = fields.Selection([
('draft', 'Draft'),
('done', 'Done'),
@@ -44,12 +47,13 @@ class CommissionResult(models.Model):
def _assign_type_selection(self):
return self.env['commission.profile.assignment']._assign_type_selection()
@api.depends('line_ids.commission_amount')
def _compute_amount_total(self):
rg_res = self.env['account.move.line'].read_group([('commission_result_id', 'in', self.ids)], ['commission_result_id', 'commission_amount:sum'], ['commission_result_id'])
mapped_data = dict([(x['commission_result_id'][0], x['commission_amount']) for x in rg_res])
@api.depends('line_ids.commission_amount', 'line_ids.commission_base')
def _compute_totals(self):
rg_res = self.env['account.move.line'].read_group([('commission_result_id', 'in', self.ids)], ['commission_result_id', 'commission_amount:sum', 'commission_base:sum'], ['commission_result_id'])
mapped_data = dict([(x['commission_result_id'][0], {'amount': x['commission_amount'], 'base': x['commission_base']}) for x in rg_res])
for rec in self:
rec.amount_total = mapped_data.get(rec.id, 0)
rec.amount_total = mapped_data.get(rec.id, {}).get('amount')
rec.base_total = mapped_data.get(rec.id, {}).get('base')
def unlink(self):
for result in self:

View File

@@ -34,7 +34,10 @@ class CommissionResultXlsx(models.AbstractModel):
sheet.write(i, 0, _('Currency'), styles['subtitle'])
sheet.write(i, 1, result.company_id.currency_id.name, styles['subtitle'])
i += 1
sheet.write(i, 0, _('Total Amount'), styles['subtitle'])
sheet.write(i, 0, _('Base Total'), styles['subtitle'])
sheet.write(i, 1, result.base_total, styles['subtitle_amount'])
i += 1
sheet.write(i, 0, _('Amount Total'), styles['subtitle'])
sheet.write(i, 1, result.amount_total, styles['subtitle_amount'])
i += 3
cols = self._prepare_xlsx_cols()

View File

@@ -24,6 +24,7 @@
<field name="date_range_id"/>
<field name="date_start"/>
<field name="date_end"/>
<field name="base_total"/>
<field name="amount_total"/>
<field name="company_currency_id" invisible="1"/>
<field name="company_id" invisible="1"/>
@@ -48,7 +49,7 @@
<field name="price_unit" string="Price" optional="hide"/>
<field name="discount" string="Disc.%" optional="hide"/>
<field name="price_subtotal" optional="hide" string="Invoiced Amount"/>
<field name="commission_base"/>
<field name="commission_base" sum="1"/>
<field name="commission_rate" string="Rate (%)"/>
<field name="commission_amount" sum="1"/>
<field name="commission_rule_id" optional="hide"/>
@@ -79,6 +80,7 @@
<field name="assign_type" optional="hide" widget="badge" decoration-warning="assign_type == 'user'"/>
<field name="company_currency_id" invisible="1"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="base_total" sum="1" optional="hide"/>
<field name="amount_total" sum="1" optional="show"/>
<field name="state" decoration-info="state == 'draft'" decoration-success="state == 'done'" widget="badge"/>
</tree>