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

[add] production & subcontracting values

parent 2941be6c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# Copyright 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models, report
from . import controllers, models, report
......@@ -11,10 +11,14 @@
"security/ir.model.access.csv",
# templates
"templates/account_invoice_templates.xml",
"templates/invoice_allocation_templates.xml",
# templates
"report/account_invoice_employee_report.xml",
# views
"views/assets.xml",
"views/account_invoice_views.xml",
"views/res_partner_views.xml",
# menus
"views/menus.xml",
],
}
......@@ -8,10 +8,18 @@ class AccountInvoice(models.Model):
_inherit = "account.invoice"
with_detail = fields.Boolean("Facture avec détail", default=False)
subcontracting_amount = fields.Monetary("Montant sous-traitance (HT)", track_visibility=True,)
expense_amount = fields.Monetary("Montant frais (HT)", track_visibility=True,)
production_amount = fields.Monetary(
string="CA production",
compute="_compute_production_amount",
store=True,
)
employee_allocation_ids = fields.One2many(
comodel_name="account.invoice.employee.assign",
inverse_name="invoice_id",
string="Ventilation facture",
tracking=True,
)
is_allocated = fields.Boolean(
string="Facture ventilée",
......@@ -25,6 +33,7 @@ class AccountInvoice(models.Model):
store=True,
default=False,
)
suspicious_client = fields.Boolean("Client douteux", default=False, tracking=True,)
# ------------------------------------------------------
# Computed field
......@@ -42,3 +51,28 @@ class AccountInvoice(models.Model):
else:
invoice.is_allocated = False
invoice.is_allocation_error = False
@api.depends("amount_untaxed_signed", "subcontracting_amount", "expense_amount")
@api.multi
def _compute_production_amount(self):
for invoice in self:
invoice.production_amount = (
invoice.amount_untaxed_signed
- invoice.subcontracting_amount
- invoice.expense_amount
)
# ------------------------------------------------------
# Business function
# ------------------------------------------------------
def get_employee_allocation(self, partner_id):
self.ensure_one()
emp_values = self.employee_allocation_ids.filtered(
lambda e: e.partner_id == partner_id
)
return sum(emp_values.mapped("percentage"))
def create_employee_lines(self, vals):
self.ensure_one()
self.employee_allocation_ids.unlink()
self.update(vals)
......@@ -36,3 +36,53 @@ class AccountInvoiceEmployeeAssign(models.Model):
for record in self:
if record.percentage < 0 or record.percentage > 100:
raise UserError(_("Le pourcentage doit être entre 0 et 100"))
# ------------------------------------------------------
# Override ORM
# ------------------------------------------------------
@api.model
def create(self, vals):
res = super(AccountInvoiceEmployeeAssign, self).create(vals)
if vals:
message = "Création ligne d'affectation : "
for val in vals:
message += (
self.env["res.partner"].browse(val.get("partner_id")).name
+ " - " + val.get("percent") + "%"
)
res.invoice_id.message_post(message)
return res
@api.model
def create(self, vals):
res = super(AccountInvoiceEmployeeAssign, self).create(vals)
if vals:
print(vals)
message = "<strong>Affectation</strong> | Création ligne d'affectation : "
message += (
self.env["res.partner"].browse(vals.get("partner_id")).name
+ " - " + str(vals.get("percentage")) + "%"
)
res.invoice_id.message_post(body=message)
return res
@api.multi
def write(self, vals):
for line in self:
message = (
"<strong>Affectation</strong> | Modification de la ligne : "
+ line.partner_id.name + " - " + str(line.percentage) + "%"
)
line.invoice_id.message_post(body=message)
result = super(AccountInvoiceEmployeeAssign, self).write(vals)
return result
@api.multi
def unlink(self):
for line in self:
message = (
"<strong>Affectation</strong> | Suppression de la ligne : "
+ line.partner_id.name + " - " + str(line.percentage) + "%"
)
line.invoice_id.message_post(body=message)
return super(AccountInvoiceEmployeeAssign, self).unlink()
......@@ -16,7 +16,8 @@ class AccountInvoiceEmployeeReport(models.Model):
string="Facture",
readonly=True,
)
amount_untaxed_signed = fields.Monetary("Montant H.T", readonly=True)
amount_untaxed_signed = fields.Monetary("Facturé H.T", readonly=True)
production_amount = fields.Monetary("Production H.T", readonly=True)
state = fields.Selection(
[
("open", "Ouverte"),
......@@ -47,6 +48,7 @@ class AccountInvoiceEmployeeReport(models.Model):
"user_id",
"amount_untaxed_signed",
"date_invoice",
"production_amount",
],
"account.invoice.employee.assign": [
"partner_id",
......@@ -63,13 +65,14 @@ class AccountInvoiceEmployeeReport(models.Model):
e.id,
i.id as "invoice_id",
i.date_invoice,
i.production_amount,
i.amount_untaxed_signed,
i.state,
i.user_id,
i.currency_id,
e.partner_id,
e.percentage,
i.amount_untaxed_signed * e.percentage / 100 as "revenue"
i.production_amount * e.percentage / 100 as "revenue"
FROM
account_invoice_employee_assign e
LEFT JOIN
......
......@@ -44,6 +44,7 @@
<field name="revenue" widget="monetary" />
<field name="user_id" />
<field name="invoice_id" />
<field name="production_amount" />
<field name="amount_untaxed_signed" />
<field name="state" />
</tree>
......
......@@ -3,6 +3,7 @@
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<!-- FORM -->
<record id="legicoop_invoice_form" model="ir.ui.view">
<field name="name">legicoop.account.invoice.form</field>
<field name="model">account.invoice</field>
......@@ -11,6 +12,7 @@
<!-- Détail de la facture -->
<xpath expr="//field[@name='payment_term_id']" position="after">
<field name="with_detail" />
<field name="suspicious_client" widget="boolean_toggle" />
</xpath>
<xpath
expr="//page[@name='other_info']/group/group[2]/field[@name='origin']"
......@@ -21,6 +23,12 @@
<!-- Ventilation de la facture -->
<xpath expr="//notebook" position="inside">
<page name="employee_assign" string="Répartition par employé">
<group>
<group>
<field name="subcontracting_amount"/>
<field name="expense_amount"/>
</group>
</group>
<field name="is_allocation_error" invisible="1" />
<div
class="alert alert-danger"
......@@ -65,6 +73,12 @@
sum="Total HT"
/>
</xpath>
<xpath
expr="//field[@name='state']"
position="after"
>
<field name="suspicious_client" widget="boolean_toggle" />
</xpath>
</field>
</record>
......@@ -75,6 +89,12 @@
<field name="inherit_id" ref="account.view_account_invoice_filter" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='late']" position="after">
<separator />
<filter
string="Clients douteur"
name="is_suspicious"
domain="[('suspicious_client', '=', True)]"
/>
<separator />
<filter
string="Factures à répartir"
......
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