Skip to content

Commit

Permalink
[MIG] account_interests: Migration to 17.0
Browse files Browse the repository at this point in the history
closes #482

Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
ica-adhoc authored and rov-adhoc committed May 13, 2024
1 parent 47da27b commit 591bdc8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions account_interests/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Interests Management',
'version': "16.0.1.1.0",
'version': "17.0.1.1.0",
'category': 'Accounting',
'sequence': 14,
'summary': 'Calculate interests for selected partners',
Expand All @@ -34,6 +34,6 @@
'data/ir_cron_data.xml',
'security/ir.model.access.csv',
],
'installable': False,
'installable': True,
'application': False,
}
17 changes: 5 additions & 12 deletions account_interests/models/res_company_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,18 @@ def create_invoices(self, to_date, groupby='partner_id'):
('company_id', '=', self.company_id.id)], limit=1)

move_line_domain = self._get_move_line_domains(to_date)

# Check if a filter is set
if self.domain:
move_line_domain += safe_eval(self.domain)

fields = ['id', 'amount_residual', 'partner_id', 'account_id']
if groupby not in fields:
fields += [groupby]
fields = ['id:recordset', 'amount_residual:sum', 'partner_id:recordset', 'account_id:recordset']

move_line = self.env['account.move.line']
grouped_lines = move_line.read_group(
grouped_lines = move_line._read_group(
domain=move_line_domain,
fields=fields,
groupby=[groupby],
aggregates=fields,
)

self = self.with_context(
company_id=self.company_id.id,
mail_notrack=True,
Expand All @@ -167,8 +163,7 @@ def create_invoices(self, to_date, groupby='partner_id'):
total_items = len(grouped_lines)
_logger.info('%s interest invoices will be generated', total_items)
for idx, line in enumerate(grouped_lines):

debt = line['amount_residual']
debt = line[2]

if not debt or debt <= 0.0:
_logger.info("Debt is negative, skipping...")
Expand All @@ -177,12 +172,10 @@ def create_invoices(self, to_date, groupby='partner_id'):
_logger.info(
'Creating Interest Invoice (%s of %s) with values:\n%s',
idx + 1, total_items, line)
partner_id = line[groupby][0]

partner_id = line[0].id
partner = self.env['res.partner'].browse(partner_id)
move_vals = self._prepare_interest_invoice(
partner, debt, to_date, journal)

move = self.env['account.move'].create(move_vals)

if self.automatic_validation:
Expand Down
2 changes: 1 addition & 1 deletion account_interests/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_company_interest_all,access_res_company_interest_all,model_res_company_interest,,1,0,0,0
access_res_company_interest_all,access_res_company_interest_all,model_res_company_interest,base.group_user,1,0,0,0
access_res_company_interest_manager,access_res_company_interest_manager,model_res_company_interest,account.group_account_manager,1,1,1,1
2 changes: 1 addition & 1 deletion account_interests/views/res_company_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<separator string="Intereses Automáticos"/>
<field name="interest_ids" context="{'default_company_id': id}">
<tree>
<field name="company_id" invisible="1" required="0"/>
<field name="company_id" required="0" invisible="1"/>
<field name="receivable_account_ids" widget="many2many_tags"/>
<field name="interest_product_id"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
Expand Down

0 comments on commit 591bdc8

Please sign in to comment.