Skip to content
Extraits de code Groupes Projets
Valider f8989798 rédigé par Jordan - Le Filament's avatar Jordan - Le Filament
Parcourir les fichiers

Merge branch '12.0-refactor-cotiz' into '12.0-dev'

12.0 refactor cotiz

See merge request !1
parents 7cf12e5a a4aeac6f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!212.0 dev,!112.0 refactor cotiz
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
"security/ir.model.access.csv", "security/ir.model.access.csv",
"views/account_invoice.xml", "views/account_invoice.xml",
"views/account_move.xml", "views/account_move.xml",
"views/account_payment_term.xml",
"views/account_payment_order.xml", "views/account_payment_order.xml",
"views/account_payment_line.xml", "views/account_payment_line.xml",
"views/res_config_settings.xml", "views/res_config_settings.xml",
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
from . import account_invoice from . import account_invoice
from . import account_payment_order from . import account_payment_order
from . import account_payment_term
from . import chart_template from . import chart_template
from . import res_company from . import res_company
from . import res_config_settings from . import res_config_settings
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
from datetime import datetime from datetime import datetime
import json import json
from odoo import models, fields, api, _ from odoo import models, fields, api
from odoo.exceptions import UserError
class ScopAccountInvoice(models.Model): class ScopAccountInvoice(models.Model):
...@@ -49,14 +48,6 @@ class ScopAccountInvoice(models.Model): ...@@ -49,14 +48,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',
...@@ -84,123 +75,6 @@ class ScopAccountInvoice(models.Model): ...@@ -84,123 +75,6 @@ class ScopAccountInvoice(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Override Parent # Override Parent
# ------------------------------------------------------ # ------------------------------------------------------
@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:
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.one @api.one
def _get_outstanding_info_JSON(self): def _get_outstanding_info_JSON(self):
super(ScopAccountInvoice, self)._get_outstanding_info_JSON() super(ScopAccountInvoice, self)._get_outstanding_info_JSON()
...@@ -233,48 +107,3 @@ class ScopAccountInvoice(models.Model): ...@@ -233,48 +107,3 @@ class ScopAccountInvoice(models.Model):
'invoice': line.invoice_id.number 'invoice': line.invoice_id.number
}) })
self.outstanding_credits_debits_widget = json.dumps(info) self.outstanding_credits_debits_widget = json.dumps(info)
# ------------------------------------------------------
# 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
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
# Copyright 2020 Le Filament
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, api
class AccountPaymentTerm(models.Model):
_inherit = 'account.payment.term'
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)
...@@ -14,12 +14,6 @@ class ScopCotisationCompany(models.Model): ...@@ -14,12 +14,6 @@ class ScopCotisationCompany(models.Model):
domain="[('type', '=', 'sale')]" domain="[('type', '=', 'sale')]"
) )
contribution_default_payment_term_id = fields.Many2one(
comodel_name='account.payment.term',
string="Conditions de paiement par défaut pour les cotisations",
domain=[('is_contribution', '=', True)],
)
tag_cotiz_id = fields.Many2one( tag_cotiz_id = fields.Many2one(
comodel_name='res.partner.category', comodel_name='res.partner.category',
string='Etiquette de cotisation', string='Etiquette de cotisation',
......
# © 2020 Le Filament (<http://www.le-filament.com>) # © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models, api from odoo import fields, models
class CotisationsConfigSettings(models.TransientModel): class CotisationsConfigSettings(models.TransientModel):
...@@ -18,14 +18,6 @@ class CotisationsConfigSettings(models.TransientModel): ...@@ -18,14 +18,6 @@ class CotisationsConfigSettings(models.TransientModel):
string='Journal des cotisations', string='Journal des cotisations',
domain="[('type', '=', 'sale')]") domain="[('type', '=', 'sale')]")
contribution_default_payment_term_id = fields.Many2one(
comodel_name='account.payment.term',
related="company_id.contribution_default_payment_term_id",
readonly=False,
string="Conditions de paiement par défaut pour les cotisations",
domain=[('is_contribution', '=', True)],
)
tag_cotiz_id = fields.Many2one( tag_cotiz_id = fields.Many2one(
comodel_name='res.partner.category', comodel_name='res.partner.category',
related="company_id.tag_cotiz_id", related="company_id.tag_cotiz_id",
......
...@@ -37,12 +37,6 @@ class ScopCotisation(models.AbstractModel): ...@@ -37,12 +37,6 @@ class ScopCotisation(models.AbstractModel):
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
comodel_name='res.currency', related='company_id.currency_id', comodel_name='res.currency', related='company_id.currency_id',
string="Company Currency", readonly=True) string="Company Currency", readonly=True)
payment_term_id = fields.Many2one(
comodel_name='account.payment.term',
string="Conditions de paiement",
domain=[('is_contribution', '=', True)],
required=True,
)
date_cotisation = fields.Date( date_cotisation = fields.Date(
string="Date calcul cotisation", string="Date calcul cotisation",
help="Date de calcul qui apparaitra sur le bordereau de cotisation" help="Date de calcul qui apparaitra sur le bordereau de cotisation"
...@@ -84,81 +78,6 @@ class ScopCotisation(models.AbstractModel): ...@@ -84,81 +78,6 @@ class ScopCotisation(models.AbstractModel):
# ------------------------------------------------------ # ------------------------------------------------------
# Global functions # Global functions
# ------------------------------------------------------ # ------------------------------------------------------
def create_contribution(
self, product, partner, type_contribution, liasse=None, amount=0,
date=False, journal_id=False, account_id=False,
type_invoice='out_invoice', is_regul=False, bordereau=False):
"""
Create invoice from Contribution Base
:param product: product_id
:param partner: partner_id
:param type_contribution: type_contribution (CG, UR, Fédé)
:param liasse: liasse_fiscale_id (reference)
:param amount: contribution amount (float)
:param date: date invoice
:param journal_id: journal
:param account_id: customer_account_id
:param type_invoice: invoice or refund
:param is_regul: used for CG Scop regul
:return: invoice
"""
Invoice = self.env['account.invoice']
InvoiceLine = self.env['account.invoice.line']
domain = [
('partner_id', '=', partner.id),
('year', '=', self.year),
('type_contribution_id', '=', type_contribution),
]
if bordereau:
domain.append(('bordereau_id', '=', bordereau.id))
exisiting_invoice = Invoice.search(domain)
if not exisiting_invoice or is_regul:
date_invoice = date if date else self.date_cotisation
journal_id = self.company_id.contribution_journal_id \
if not journal_id else journal_id
account_id = partner.property_account_receivable_id \
if not account_id else account_id
member_invoice = Invoice.create({
'partner_id': partner.id,
'liasse_fiscale_id': liasse.id,
'type': type_invoice,
'year': self.year,
'is_contribution': True,
'type_contribution_id': type_contribution,
'journal_id': journal_id.id,
'state': 'draft',
'account_id': account_id.id,
'payment_term_id': self.payment_term_id.id,
'payment_mode_id': partner.customer_payment_mode_id.id,
'date_invoice': date_invoice,
})
else:
member_invoice = exisiting_invoice
# Création de la ligne CG Scop
exisiting_invoice_line_ids = InvoiceLine.search([
('invoice_id', '=', member_invoice.id),
('product_id', '=', product.id)
])
if not exisiting_invoice_line_ids or is_regul:
InvoiceLine.create({
'invoice_id': member_invoice.id,
'product_id': product.id,
'account_id': product.property_account_income_id.id,
'invoice_line_tax_ids': [(6, 0, product.taxes_id.ids)],
'name': product.name,
'price_unit': amount
})
else:
exisiting_invoice_line_ids[0].write({
'price_unit': amount
})
return member_invoice
@api.multi @api.multi
def get_members(self): def get_members(self):
self.ensure_one() self.ensure_one()
......
...@@ -34,6 +34,17 @@ ...@@ -34,6 +34,17 @@
<attribute name="invisible">True</attribute> <attribute name="invisible">True</attribute>
</xpath> </xpath>
<xpath expr="//field[@name='beneficiary_id']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="//field[@name='lf_note_ref_facture']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="//field[@name='team_id']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="//sheet/h1/div/label[1]" position="attributes"> <xpath expr="//sheet/h1/div/label[1]" position="attributes">
<attribute name="string">Cotisation en brouillon</attribute> <attribute name="string">Cotisation en brouillon</attribute>
</xpath> </xpath>
...@@ -52,6 +63,9 @@ ...@@ -52,6 +63,9 @@
<xpath expr="//field[@name='partner_id']" position="attributes"> <xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="string">Adhérent</attribute> <attribute name="string">Adhérent</attribute>
</xpath> </xpath>
<xpath expr="//field[@name='partner_id']" position="after">
<field name="type_contribution_id"/>
</xpath>
<xpath expr="//field[@name='date_invoice']" position="attributes"> <xpath expr="//field[@name='date_invoice']" position="attributes">
<attribute name="string">Date de cotisation</attribute> <attribute name="string">Date de cotisation</attribute>
</xpath> </xpath>
...@@ -67,6 +81,7 @@ ...@@ -67,6 +81,7 @@
<xpath expr="//field[@name='state']" position="after"> <xpath expr="//field[@name='state']" position="after">
<field name="is_sdd" invisible="1"/> <field name="is_sdd" invisible="1"/>
</xpath> </xpath>
</field> </field>
</record> </record>
......
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Copyright 2020 Le Filament
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<data>
<record id="view_payment_term_form_inherited" model="ir.ui.view">
<field name="name">account.payment.term.form</field>
<field name="model">account.payment.term</field>
<field name="inherit_id" ref="account.view_payment_term_form"/>
<field name="arch" type="xml">
<xpath expr="//group" position="after">
<group name="schedule">
<field name="is_contribution" widget="boolean_toggle"/>
</group>
</xpath>
</field>
</record>
</data>
</odoo>
\ No newline at end of file
...@@ -29,13 +29,6 @@ ...@@ -29,13 +29,6 @@
</div> </div>
<field name="contribution_journal_id" options="{'no_open': True, 'no_create': True}"/> <field name="contribution_journal_id" options="{'no_open': True, 'no_create': True}"/>
</div> </div>
<div class="o_setting_right_pane">
<label for="contribution_default_payment_term_id"/>
<div class="text-muted">
Conditions de paiement par défault
</div>
<field name="contribution_default_payment_term_id" options="{'no_open': True, 'no_create': True}"/>
</div>
<div class="o_setting_left_pane"/> <div class="o_setting_left_pane"/>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane">
<label for="tag_cotiz_id"/> <label for="tag_cotiz_id"/>
......
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