Skip to content

Commit

Permalink
[MIG] website_sale_account_invoice_commission: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohmontenegro committed Mar 26, 2024
1 parent 9c57b9d commit 8b8b374
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions account_invoice_commission/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Commission Invoices

Simple module that links a commission invoice (supplier invoice) to the commissioned invoices (customer invoices)

- Allows to set Rules Commission.

- Creates a tab in Commission Invoices (supplier invoice) that allows users to add Commisioned Invoices (customer invoice) based on settled rules commission.

- Creates a tab in Commissioned Invoices that shows the applied Commision Invoices.

TODO
====

Expand Down
14 changes: 13 additions & 1 deletion account_invoice_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,23 @@ def _compute_date_last_payment(self):
@api.depends('invoice_line_ids.commission_amount')
@api.depends_context('commissioned_partner_id')
def _compute_commission_amount(self):
commissioned_partner_id = self.invoice_user_id.partner_id.id
commissioned_partner_id = self._context.get('commissioned_partner_id')
if commissioned_partner_id:
_logger.info('Computing commission amount')
for rec in self:
rec.commission_amount = sum(
rec.mapped('invoice_line_ids.commission_amount'))
else:
self.commission_amount = 0.0

def web_read(self, specification):
""" Esto lo agregamos para propagar el contexto del commissioned_partner_id
La idea es que si esta presente el campo commissioned_invoice_ids agregamos en el contexto
el commissioned_partner_id y llamamos a super de web_read pisando estos valores. """
res = super().web_read(specification)
for vals, rec in zip(res, self):
partner_id = vals.get('partner_id')
if partner_id and partner_id.get('id') and 'commissioned_invoice_ids' in specification:
vals['commissioned_invoice_ids'] = super(AccountMove, rec).with_context(commissioned_partner_id=vals['partner_id']['id']).web_read(
{'commissioned_invoice_ids': specification['commissioned_invoice_ids']})[0]['commissioned_invoice_ids']
return res
2 changes: 1 addition & 1 deletion account_invoice_commission/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AccountMoveLine(models.Model):
)

def _compute_commission_amount(self):
commissioned_partner_id = self.move_id.invoice_user_id.partner_id.id
commissioned_partner_id = self._context.get('commissioned_partner_id')
if commissioned_partner_id:
today = fields.Date.context_today(self)
rules = self.env['account.commission.rule']
Expand Down
4 changes: 2 additions & 2 deletions website_sale_account_invoice_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Commission Invoices with Public Categories',
'version': "16.0.1.0.0",
'version': "17.0.1.0.0",
'category': 'Accounting',
'sequence': 14,
'summary': '',
Expand All @@ -37,7 +37,7 @@
],
'demo': [
],
'installable': False,
'installable': True,
'auto_install': True,
'application': False,
}

0 comments on commit 8b8b374

Please sign in to comment.