Skip to content
Extraits de code Groupes Projets
Valider e5ec96a7 rédigé par jordan's avatar jordan
Parcourir les fichiers

[add] add line to scop_contribution when validate invoice type contribution

parent 00da6167
Branches
Étiquettes v1.1.7
Aucune requête de fusion associée trouvée
...@@ -45,3 +45,55 @@ class ScopAccountInvoice(models.Model): ...@@ -45,3 +45,55 @@ class ScopAccountInvoice(models.Model):
index=True, index=True,
default=_default_ur) default=_default_ur)
@api.multi
def action_invoice_open(self):
"""
Création d'une ligne dans scop.contribution
quand une facture cotisation devient valide
"""
results = super(ScopAccountInvoice, self).action_invoice_open()
for inv in self:
if inv.is_contribution:
year = inv.year
account_type_receivable_ids = inv.env[
'account.account'].search([
('user_type_id', '=', inv.env.ref(
'account.data_account_type_receivable').id)
]).mapped('id')
account_move_line_ids = inv.env['account.move.line'].search([
('invoice_id', '=', inv.id),
('account_id', 'in', account_type_receivable_ids)
]).filtered(lambda l: l.date_maturity.year == year)
inv.env['scop.contribution'].create({
'partner_id': inv.partner_id.id,
'type_id': inv.type_contribution_id.id,
'year': inv.year,
'calculation_date': fields.Datetime.now(),
'amount_calculated': inv.amount_aura_calculated,
'amount_called': inv.amount_total,
'spreading': len(
account_move_line_ids.mapped('date_maturity')),
'quarter_1': inv.get_last_maturity_date(
[1, 2, 3], account_move_line_ids),
'quarter_2': inv.get_last_maturity_date(
[4, 5, 6], account_move_line_ids),
'quarter_3': inv.get_last_maturity_date(
[7, 8, 9], account_move_line_ids),
'quarter_4': inv.get_last_maturity_date(
[10, 11, 12], account_move_line_ids),
'invoice_id': inv.id,
})
return results
def get_last_maturity_date(self, months, account_move_line_ids):
"""
Get the last maturity date from account_move_line
for a certain period (months = [])
:param months:
:param account_move_line_ids:
:return: last date_maturity
"""
line_ids = account_move_line_ids.filtered(
lambda l: l.date_maturity.month in months)
return line_ids[-1].date_maturity if line_ids else None
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter