[IMP] commission_simple: allow to restart commission computation on the same period without deleting all commission results
This commit is contained in:
committed by
Florian da Costa
parent
ffcaff5ab0
commit
e39edc14c3
@@ -103,6 +103,7 @@ class CommissionProfileAssignment(models.Model):
|
|||||||
'profile_id': self.profile_id.id,
|
'profile_id': self.profile_id.id,
|
||||||
'date_range_id': date_range.id,
|
'date_range_id': date_range.id,
|
||||||
'assign_type': self.assign_type,
|
'assign_type': self.assign_type,
|
||||||
|
'assignment_id': self.id,
|
||||||
'company_id': self.company_id.id,
|
'company_id': self.company_id.id,
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class CommissionResult(models.Model):
|
|||||||
readonly=True, tracking=True)
|
readonly=True, tracking=True)
|
||||||
profile_id = fields.Many2one(
|
profile_id = fields.Many2one(
|
||||||
'commission.profile', string='Commission Profile', readonly=True, tracking=True)
|
'commission.profile', string='Commission Profile', readonly=True, tracking=True)
|
||||||
|
assignment_id = fields.Many2one(
|
||||||
|
'commission.profile.assignment', string="Commission Profile Assignment", readonly=True)
|
||||||
assign_type = fields.Selection('_assign_type_selection', readonly=True, tracking=True)
|
assign_type = fields.Selection('_assign_type_selection', readonly=True, tracking=True)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
'res.company', string='Company', ondelete='cascade',
|
'res.company', string='Company', ondelete='cascade',
|
||||||
|
|||||||
@@ -46,17 +46,12 @@ class CommissionCompute(models.TransientModel):
|
|||||||
if not self.date_start:
|
if not self.date_start:
|
||||||
raise UserError(_("Missing Period Start Date."))
|
raise UserError(_("Missing Period Start Date."))
|
||||||
creso = self.env['commission.result']
|
creso = self.env['commission.result']
|
||||||
existing_commissions = creso.search([
|
existing_commissions = creso.search_read([
|
||||||
('date_start', '=', self.date_start),
|
('date_start', '=', self.date_start),
|
||||||
('company_id', '=', self.company_id.id),
|
('company_id', '=', self.company_id.id),
|
||||||
])
|
], ['assignment_id'])
|
||||||
if existing_commissions:
|
exclude_assignment_ids = [x['assignment_id'][0] for x in existing_commissions if x['assignment_id']]
|
||||||
raise UserError(_(
|
com_result_ids = self._core_compute(exclude_assignment_ids)
|
||||||
'%(count)s commissions already exist(s) with start date %(date_start)s in company %(company)s.',
|
|
||||||
count=len(existing_commissions),
|
|
||||||
date_start=format_date(self.env, self.date_start),
|
|
||||||
company=self.company_id.display_name))
|
|
||||||
com_result_ids = self._core_compute()
|
|
||||||
if not com_result_ids:
|
if not com_result_ids:
|
||||||
raise UserError(_('No commissions generated.'))
|
raise UserError(_('No commissions generated.'))
|
||||||
action = self.env['ir.actions.actions']._for_xml_id(
|
action = self.env['ir.actions.actions']._for_xml_id(
|
||||||
@@ -67,10 +62,11 @@ class CommissionCompute(models.TransientModel):
|
|||||||
})
|
})
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def _core_compute(self):
|
def _core_compute(self, exclude_assignment_ids):
|
||||||
rules = self.env['commission.rule'].load_all_rules()
|
rules = self.env['commission.rule'].load_all_rules()
|
||||||
com_result_ids = []
|
com_result_ids = []
|
||||||
assignments = self.env['commission.profile.assignment'].search([('company_id', '=', self.company_id.id)])
|
assignments = self.env['commission.profile.assignment'].search(
|
||||||
|
[('company_id', '=', self.company_id.id), ('id', 'not in', exclude_assignment_ids)])
|
||||||
date_range_type2date_range = {}
|
date_range_type2date_range = {}
|
||||||
for assignment in assignments:
|
for assignment in assignments:
|
||||||
profile = assignment.profile_id
|
profile = assignment.profile_id
|
||||||
|
|||||||
Reference in New Issue
Block a user