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

[update] remove useless functions to generate move_line according to payment terms

parent 70caae1d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -49,14 +49,6 @@ class ScopAccountInvoice(models.Model): ...@@ -49,14 +49,6 @@ class ScopAccountInvoice(models.Model):
contribution_id = fields.Many2one( contribution_id = fields.Many2one(
comodel_name='scop.contribution', comodel_name='scop.contribution',
string='Ligne de cotisation') string='Ligne de cotisation')
nb_quarter = fields.Selection(
string='Nombre de trimestres de cotisation',
selection=[(1, '1'),
(2, '2'),
(3, '3'),
(4, '4')],
default=4,
required=True)
is_sdd = fields.Boolean( is_sdd = fields.Boolean(
'Au prélèvement', 'Au prélèvement',
compute='compute_is_sdd', compute='compute_is_sdd',
...@@ -91,115 +83,115 @@ class ScopAccountInvoice(models.Model): ...@@ -91,115 +83,115 @@ class ScopAccountInvoice(models.Model):
quand une facture cotisation devient valide quand une facture cotisation devient valide
""" """
results = super(ScopAccountInvoice, self).action_invoice_open() results = super(ScopAccountInvoice, self).action_invoice_open()
for inv in self: # for inv in self:
if inv.is_contribution: # if inv.is_contribution:
inv.set_scop_contribution() # inv.set_scop_contribution()
return results return results
@api.multi # @api.multi
def action_move_create(self): # def action_move_create(self):
""" # """
Complete override parent # Complete override parent
Pass invoice in payment_term.compute function to generate payment # Pass invoice in payment_term.compute function to generate payment
schedule # schedule
:return: True # :return: True
""" # """
account_move = self.env['account.move'] # account_move = self.env['account.move']
#
for inv in self: # for inv in self:
if not inv.journal_id.sequence_id: # if not inv.journal_id.sequence_id:
raise UserError(_('Please define sequence on the journal related to this invoice.')) # raise UserError(_('Please define sequence on the journal related to this invoice.'))
if not inv.invoice_line_ids.filtered(lambda line: line.account_id): # if not inv.invoice_line_ids.filtered(lambda line: line.account_id):
raise UserError(_('Please add at least one invoice line.')) # raise UserError(_('Please add at least one invoice line.'))
if inv.move_id: # if inv.move_id:
continue # continue
#
if not inv.date_invoice: # if not inv.date_invoice:
inv.write({'date_invoice': fields.Date.context_today(self)}) # inv.write({'date_invoice': fields.Date.context_today(self)})
if not inv.date_due: # if not inv.date_due:
inv.write({'date_due': inv.date_invoice}) # inv.write({'date_due': inv.date_invoice})
company_currency = inv.company_id.currency_id # company_currency = inv.company_id.currency_id
#
# create move lines # # create move lines
# (one per invoice line + eventual taxes and analytic lines) # # (one per invoice line + eventual taxes and analytic lines)
iml = inv.invoice_line_move_line_get() # iml = inv.invoice_line_move_line_get()
iml += inv.tax_line_move_line_get() # iml += inv.tax_line_move_line_get()
#
diff_currency = inv.currency_id != company_currency # diff_currency = inv.currency_id != company_currency
# create one move line for the total and possibly adjust # # create one move line for the total and possibly adjust
# the other lines amount # # the other lines amount
total, total_currency, iml = inv.compute_invoice_totals( # total, total_currency, iml = inv.compute_invoice_totals(
company_currency, iml) # company_currency, iml)
#
name = inv.name or '' # name = inv.name or ''
if inv.payment_term_id: # if inv.payment_term_id:
totlines = inv.payment_term_id.with_context( # totlines = inv.payment_term_id.with_context(
currency_id=company_currency.id).compute(total, inv.date_invoice, inv)[0] # currency_id=company_currency.id).compute(total, inv.date_invoice, inv)[0]
res_amount_currency = total_currency # res_amount_currency = total_currency
for i, t in enumerate(totlines): # for i, t in enumerate(totlines):
if inv.currency_id != company_currency: # if inv.currency_id != company_currency:
amount_currency = company_currency._convert( # amount_currency = company_currency._convert(
t[1], # t[1],
inv.currency_id, # inv.currency_id,
inv.company_id, # inv.company_id,
inv._get_currency_rate_date() or fields.Date.today()) # inv._get_currency_rate_date() or fields.Date.today())
else: # else:
amount_currency = False # amount_currency = False
#
# last line: add the diff # # last line: add the diff
res_amount_currency -= amount_currency or 0 # res_amount_currency -= amount_currency or 0
if i + 1 == len(totlines): # if i + 1 == len(totlines):
amount_currency += res_amount_currency # amount_currency += res_amount_currency
#
iml.append({ # iml.append({
'type': 'dest', # 'type': 'dest',
'name': name, # 'name': name,
'price': t[1], # 'price': t[1],
'account_id': inv.account_id.id, # 'account_id': inv.account_id.id,
'date_maturity': t[0], # 'date_maturity': t[0],
'amount_currency': diff_currency and amount_currency, # 'amount_currency': diff_currency and amount_currency,
'currency_id': diff_currency and inv.currency_id.id, # 'currency_id': diff_currency and inv.currency_id.id,
'invoice_id': inv.id # 'invoice_id': inv.id
}) # })
else: # else:
iml.append({ # iml.append({
'type': 'dest', # 'type': 'dest',
'name': name, # 'name': name,
'price': total, # 'price': total,
'account_id': inv.account_id.id, # 'account_id': inv.account_id.id,
'date_maturity': inv.date_due, # 'date_maturity': inv.date_due,
'amount_currency': diff_currency and total_currency, # 'amount_currency': diff_currency and total_currency,
'currency_id': diff_currency and inv.currency_id.id, # 'currency_id': diff_currency and inv.currency_id.id,
'invoice_id': inv.id # 'invoice_id': inv.id
}) # })
part = self.env['res.partner']._find_accounting_partner( # part = self.env['res.partner']._find_accounting_partner(
inv.partner_id) # inv.partner_id)
line = [(0, 0, self.line_get_convert(l, part.id)) for l in iml] # line = [(0, 0, self.line_get_convert(l, part.id)) for l in iml]
line = inv.group_lines(iml, line) # line = inv.group_lines(iml, line)
#
line = inv.finalize_invoice_move_lines(line) # line = inv.finalize_invoice_move_lines(line)
#
date = inv.date or inv.date_invoice # date = inv.date or inv.date_invoice
move_vals = { # move_vals = {
'ref': inv.reference, # 'ref': inv.reference,
'line_ids': line, # 'line_ids': line,
'journal_id': inv.journal_id.id, # 'journal_id': inv.journal_id.id,
'date': date, # 'date': date,
'narration': inv.comment, # 'narration': inv.comment,
} # }
move = account_move.create(move_vals) # move = account_move.create(move_vals)
# Pass invoice in method post: used if you want to get the same # # Pass invoice in method post: used if you want to get the same
# account move reference when creating the same invoice # # account move reference when creating the same invoice
# after a cancelled one: # # after a cancelled one:
move.post(invoice = inv) # move.post(invoice = inv)
# make the invoice point to that move # # make the invoice point to that move
vals = { # vals = {
'move_id': move.id, # 'move_id': move.id,
'date': date, # 'date': date,
'move_name': move.name, # 'move_name': move.name,
} # }
inv.write(vals) # inv.write(vals)
return True # return True
@api.one @api.one
def _get_outstanding_info_JSON(self): def _get_outstanding_info_JSON(self):
...@@ -237,44 +229,44 @@ class ScopAccountInvoice(models.Model): ...@@ -237,44 +229,44 @@ class ScopAccountInvoice(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Common Function # Common Function
# ------------------------------------------------------ # ------------------------------------------------------
@api.multi # @api.multi
def set_scop_contribution(self): # def set_scop_contribution(self):
""" # """
Création d'une ligne dans scop.contribution # Création d'une ligne dans scop.contribution
""" # """
self.ensure_one() # self.ensure_one()
if self.is_contribution: # if self.is_contribution:
year = self.year # year = self.year
# Get existing contribution for this year # # Get existing contribution for this year
contrib_id = self.env['scop.contribution'].search([ # contrib_id = self.env['scop.contribution'].search([
('partner_id', '=', self.partner_id.id), # ('partner_id', '=', self.partner_id.id),
('year', '=', year), # ('year', '=', year),
('type_id', '=', self.type_contribution_id.id) # ('type_id', '=', self.type_contribution_id.id)
]) # ])
#
# Create scop.contribution line if not exists # # Create scop.contribution line if not exists
# for year, partner and type # # for year, partner and type
if not contrib_id: # if not contrib_id:
contrib_line = self.env['scop.contribution'].create({ # contrib_line = self.env['scop.contribution'].create({
'partner_id': self.partner_id.id, # 'partner_id': self.partner_id.id,
'type_id': self.type_contribution_id.id, # 'type_id': self.type_contribution_id.id,
'year': self.year, # 'year': self.year,
'calculation_date': fields.Datetime.now(), # 'calculation_date': fields.Datetime.now(),
'amount_calculated': self.amount_total, # 'amount_calculated': self.amount_total,
'amount_called': self.amount_total, # 'amount_called': self.amount_total,
'spreading': self.nb_quarter, # 'spreading': self.nb_quarter,
'invoice_id': self.id, # 'invoice_id': self.id,
}) # })
else: # else:
contrib_line = self.set_scop_contribution_hook(contrib_id) # contrib_line = self.set_scop_contribution_hook(contrib_id)
self.contribution_id = contrib_line.id # self.contribution_id = contrib_line.id
return contrib_line # return contrib_line
return False # return False
def set_scop_contribution_hook(self, contrib_id): # def set_scop_contribution_hook(self, contrib_id):
""" # """
Function that can be inherited if a contrib line already exists # Function that can be inherited if a contrib line already exists
:param contrib_id: scop.contribution line # :param contrib_id: scop.contribution line
:return: scop.contribution # :return: scop.contribution
""" # """
return contrib_id # return contrib_id
...@@ -9,45 +9,45 @@ class AccountPaymentTerm(models.Model): ...@@ -9,45 +9,45 @@ class AccountPaymentTerm(models.Model):
is_contribution = fields.Boolean('Conditions de paiement des cotisations') is_contribution = fields.Boolean('Conditions de paiement des cotisations')
def compute(self, value, date_ref=False, invoice=False): # def compute(self, value, date_ref=False, invoice=False):
""" # """
Override la fonction compute du modèle account.payment.term # Override la fonction compute du modèle account.payment.term
La fonction initiale checke les conditions de paiement et crée # La fonction initiale checke les conditions de paiement et crée
les lignes de paiement associées # les lignes de paiement associées
#
L'héritage permet de créer un échéancier en fonction de celui # L'héritage permet de créer un échéancier en fonction de celui
défini sur la base de cotisations # défini sur la base de cotisations
""" # """
date_ref = date_ref or fields.Date.today() # date_ref = date_ref or fields.Date.today()
amount = value # amount = value
sign = value < 0 and -1 or 1 # sign = value < 0 and -1 or 1
if self.env.context.get('currency_id'): # if self.env.context.get('currency_id'):
currency = self.env['res.currency'].browse( # currency = self.env['res.currency'].browse(
self.env.context['currency_id']) # self.env.context['currency_id'])
else: # else:
currency = self.env.user.company_id.currency_id # currency = self.env.user.company_id.currency_id
#
# si base de cotisation # # si base de cotisation
if self.is_contribution and invoice and (invoice.cotisation_cg_id or invoice.cotisation_aura_id): # if self.is_contribution and invoice and (invoice.cotisation_cg_id or invoice.cotisation_aura_id):
result = [] # result = []
if invoice.cotisation_cg_id: # if invoice.cotisation_cg_id:
base_contrib_field = 'cotisation_cg_id' # base_contrib_field = 'cotisation_cg_id'
elif invoice.cotisation_aura_id: # elif invoice.cotisation_aura_id:
base_contrib_field = 'cotisation_aura_id' # base_contrib_field = 'cotisation_aura_id'
trimesters = { # trimesters = {
4: invoice[base_contrib_field].trimester_1, # 4: invoice[base_contrib_field].trimester_1,
3: invoice[base_contrib_field].trimester_2, # 3: invoice[base_contrib_field].trimester_2,
2: invoice[base_contrib_field].trimester_3, # 2: invoice[base_contrib_field].trimester_3,
1: invoice[base_contrib_field].trimester_4, # 1: invoice[base_contrib_field].trimester_4,
} # }
for i in range(invoice.nb_quarter, 0, -1): # for i in range(invoice.nb_quarter, 0, -1):
# Gestion de l'arrondi de la division # # Gestion de l'arrondi de la division
if i == 1: # if i == 1:
amt = currency.round(amount) # amt = currency.round(amount)
else: # else:
amt = currency.round(value / invoice.nb_quarter) # amt = currency.round(value / invoice.nb_quarter)
result.append((fields.Date.to_string(trimesters.get(i)), amt)) # result.append((fields.Date.to_string(trimesters.get(i)), amt))
amount -= amt # amount -= amt
return [result] # return [result]
else: # else:
return super(AccountPaymentTerm, self).compute(value, date_ref) # return super(AccountPaymentTerm, self).compute(value, date_ref)
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