Small fixes in commission modules
This commit is contained in:
@@ -14,7 +14,7 @@ class AccountInvoiceLine(models.Model):
|
||||
user_id = fields.Many2one(
|
||||
related='invoice_id.user_id', store=True, readonly=True)
|
||||
product_categ_id = fields.Many2one(
|
||||
related='product_id.categ_id', store=True, readonly=True)
|
||||
related='product_id.product_tmpl_id.categ_id', store=True, readonly=True)
|
||||
commission_result_id = fields.Many2one(
|
||||
'commission.result', string='Commission Result')
|
||||
commission_rule_id = fields.Many2one(
|
||||
@@ -26,17 +26,20 @@ class AccountInvoiceLine(models.Model):
|
||||
readonly=True, compute='_compute_commission_amount', store=True)
|
||||
|
||||
@api.depends('commission_rate', 'commission_base')
|
||||
def _compute_amount(self):
|
||||
def _compute_commission_amount(self):
|
||||
for line in self:
|
||||
line.commission_amount = line.commission_rate * line.commission_base / 100.0
|
||||
line.commission_amount = line.company_currency_id.round(
|
||||
line.commission_rate * line.commission_base / 100.0)
|
||||
|
||||
def compute_commission_for_one_user(self, user, date_range, rules):
|
||||
profile = user.commission_profile_id
|
||||
company = profile.company_id
|
||||
company_currency = company.currency_id
|
||||
assert profile
|
||||
domain = [
|
||||
('invoice_type', 'in', ('out_invoice', 'out_refund')),
|
||||
('date_invoice', '<=', date_range.date_end),
|
||||
('company_id', '=', self.env.user.company_id.id),
|
||||
('company_id', '=', company.id),
|
||||
('user_id', '=', user.id),
|
||||
('commission_result_id', '=', False),
|
||||
]
|
||||
@@ -61,7 +64,9 @@ class AccountInvoiceLine(models.Model):
|
||||
lvals = iline._prepare_commission_data(rule, com_result)
|
||||
if lvals:
|
||||
iline.write(lvals)
|
||||
total += lvals['commission_amount']
|
||||
total += company_currency.round(
|
||||
lvals['commission_rate'] * lvals['commission_base']
|
||||
/ 100.0)
|
||||
com_result.amount_total = total
|
||||
return com_result
|
||||
|
||||
@@ -103,6 +108,5 @@ class AccountInvoiceLine(models.Model):
|
||||
# company currency
|
||||
'commission_base': self.price_subtotal_signed,
|
||||
'commission_rate': rule['rate'],
|
||||
'commission_amount': rule['rate'] * self.price_subtotal_signed,
|
||||
}
|
||||
return lvals
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<field name="name">commission.rule.tree</field>
|
||||
<field name="model">commission.rule</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Règles de commission">
|
||||
<tree string="Commission Rules">
|
||||
<field name="profile_id" invisible="not context.get('commission_rule_main_view')"/>
|
||||
<field name="applied_on"/>
|
||||
<field name="date_start"/>
|
||||
|
||||
@@ -22,7 +22,8 @@ class CommissionCompute(models.TransientModel):
|
||||
today = fields.Date.from_string(fields.Date.context_today(self))
|
||||
first_day_last_month = today + relativedelta(months=-1, day=1)
|
||||
dranges = self.env['date.range'].search([
|
||||
('company_id', '=', self.env.user.company_id.id),
|
||||
'|', ('company_id', '=', self.env.user.company_id.id),
|
||||
('company_id', '=', False),
|
||||
('type_id', '=', drange_type.id),
|
||||
('date_start', '=', fields.Date.to_string(first_day_last_month))
|
||||
])
|
||||
|
||||
@@ -15,5 +15,13 @@
|
||||
<field name="domain_force">[('user_id', '=', user.id)]</field>
|
||||
</record>
|
||||
|
||||
<record id="commission_result_see_all_rule" model="ir.rule">
|
||||
<field name="name">Commission Result for Sales Manager (see all)</field>
|
||||
<field name="model_id" ref="commission_simple.model_commission_result"/>
|
||||
<field name="groups" eval="[(4, ref('sales_team.group_sale_manager'))]"/>
|
||||
<field name="domain_force">[(1, '=', 1)]</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user