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