From 1e2bea7d43ea4395fc20bb97d02aa0d65202a01d Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Wed, 5 Mar 2025 12:57:22 +0100 Subject: [PATCH] [UPD] remove main company from invoice employee assign --- __manifest__.py | 3 +- controllers/main.py | 4 +- models/account_invoice.py | 8 + models/account_invoice_employee_assign.py | 21 +- static/src/xml/employee_assign_form.xml | 227 --------------------- templates/invoice_allocation_templates.xml | 2 +- views/account_invoice_employee_assign.xml | 63 ++++++ views/menus.xml | 11 +- 8 files changed, 85 insertions(+), 254 deletions(-) delete mode 100755 static/src/xml/employee_assign_form.xml create mode 100644 views/account_invoice_employee_assign.xml diff --git a/__manifest__.py b/__manifest__.py index 693799c..d903b02 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -12,11 +12,12 @@ # templates "templates/account_invoice_templates.xml", "templates/invoice_allocation_templates.xml", - # templates + # report "report/account_invoice_employee_report.xml", "report/account_invoice_report.xml", # views "views/assets.xml", + "views/account_invoice_employee_assign.xml", "views/account_invoice_views.xml", "views/res_partner_views.xml", # menus diff --git a/controllers/main.py b/controllers/main.py index 42a7866..10b7ba6 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -16,9 +16,7 @@ class AccountInvoiceAllocationController(http.Controller): invoice_ids = request.env["account.invoice"].search( domain, order="date_invoice" ) - partner_ids = request.env.ref("base.main_partner") + request.env[ - "hr.employee" - ].search([]).mapped("user_id").mapped("partner_id") + partner_ids = request.env["hr.employee"].search([]).mapped("user_id").mapped("partner_id") view = request.env.ref("legicoop_account.invoice_allocation") return { "html_content": view.render( diff --git a/models/account_invoice.py b/models/account_invoice.py index dfebfad..7c5d5f4 100644 --- a/models/account_invoice.py +++ b/models/account_invoice.py @@ -51,6 +51,11 @@ class AccountInvoice(models.Model): @api.depends("employee_allocation_ids", "employee_allocation_ids.percentage") @api.multi def _compute_allocation(self): + """ + Calcule si la répartition par employé : + - is_allocated = False si aucune ligne + - is_allocation_error = True si la somme des pourcentages != 100 + """ for invoice in self: if invoice.employee_allocation_ids: invoice.is_allocated = True @@ -65,6 +70,9 @@ class AccountInvoice(models.Model): @api.depends("amount_untaxed_signed", "subcontracting_amount", "expense_amount") @api.multi def _compute_production_amount(self): + """ + Calcule le montant de la prod interne = montant facture - sous-traitance - frais + """ for invoice in self: invoice.production_amount = ( invoice.amount_untaxed_signed diff --git a/models/account_invoice_employee_assign.py b/models/account_invoice_employee_assign.py index 3da7d76..ed60d17 100644 --- a/models/account_invoice_employee_assign.py +++ b/models/account_invoice_employee_assign.py @@ -11,10 +11,7 @@ class AccountInvoiceEmployeeAssign(models.Model): @api.model def _get_partner_domain(self): - partner_ids = self.env.ref("base.main_partner") - partner_ids += ( - self.env["hr.employee"].search([]).mapped("user_id").mapped("partner_id") - ) + partner_ids = self.env["hr.employee"].search([]).mapped("user_id").mapped("partner_id") return [("id", "in", partner_ids.ids)] invoice_id = fields.Many2one( @@ -44,22 +41,6 @@ class AccountInvoiceEmployeeAssign(models.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 diff --git a/static/src/xml/employee_assign_form.xml b/static/src/xml/employee_assign_form.xml deleted file mode 100755 index f3bf780..0000000 --- a/static/src/xml/employee_assign_form.xml +++ /dev/null @@ -1,227 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- Copyright 2017 Le Filament (<https://www.le-filament.com>) - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> -<templates xml:space="preserve"> - - <t t-name="EmployeeAssignForm"> - <div class="yeardashboard"> - <div class="row"> - <!-- COLONNE 1 --> - <div class="col-xs-12"> - <t t-foreach="widget.invoices" - <h3>En Cours</h3> - <!-- Facturé --> - <div class="col-xs-12"> - <div class="card"> - <div class="card-body"> - <h5 class="card-title">Facturé</h5> - <p class="card-number"> - <a id="facture" t-attf-data-fiscalyear="#{widget.values.fiscal_year}" > - <t t-esc="widget.render_monetary(widget.values.facture)"></t> - </a> - </p> - </div> - </div> - </div> - <!-- Commandes --> - <div class="col-xs-12"> - <div class="card"> - <div class="card-body"> - <h5 class="card-title">Commandes en cours</h5> - <p class="card-number"> - <a id="commandes"> - <t t-esc="widget.render_monetary(widget.values.commandes)"></t> - </a> - </p> - </div> - </div> - </div> - <!-- Pipe --> - <div class="col-xs-12 dashboard-tab"> - <ul class="nav nav-tabs" id="myTab1"> - <li class="nav-item"> - <a class="nav-link active" data-toggle="tab" href="#pipe">Pipe</a> - </li> - <li class="nav-item"> - <a class="nav-link" data-toggle="tab" href="#pipe_n1">Pipe N+1</a> - </li> - </ul> - <div class="tab-content card-tab" id="myTab1Content"> - <div id="pipe" class="tab-pane fade show active in"> - <p class="card-number"> - <a id="pipe_link" t-attf-data-fiscalyearnext="#{widget.values.fiscal_year_next}" > - <t t-esc="widget.render_monetary(widget.values.pipe)"></t> - </a> - </p> - </div> - <div id="pipe_n1" class="tab-pane fade"> - <p class="card-number"> - <a id="pipe_n1_link" t-attf-data-fiscalyearnext="#{widget.values.fiscal_year_next}" > - <t t-esc="widget.render_monetary(widget.values.pipe_n1)"></t> - </a> - </p> - </div> - </div> - </div> - </div> - <!-- COLONNE 2 --> - <div class="col-xs-12 col-sm-6 col-md-4"> - <h3>Objectif</h3> - <div class="col-xs-12"> - <div class="card"> - <div class="card-body"> - <h5 class="card-title">Target</h5> - <p class="card-number"> - <t t-esc="widget.render_monetary(widget.values.target)"></t> - </p> - <canvas id="target" width="auto" height="125"></canvas> - <!-- <div id="hchart" ></div> --> - <table class="table-legend"> - <tr> - <td style="background-color: #8ED8A2; width: 20px;"></td> - <td>Facturé</td> - <td class="nb"><t t-esc="widget.render_percent(widget.pfact)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.pfact2)"></t></td> - </tr> - <tr> - <td style="background-color: #F6DCA2; width: 20px;"></td> - <td>Commandes</td> - <td class="nb"><t t-esc="widget.render_percent(widget.pcomm)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.pcomm2)"></t></td> - </tr> - <tr> - <td style="background-color: #F6CCA2; width: 20px;"></td> - <td>Pipe Gagné</td> - <td class="nb"><t t-esc="widget.render_percent(widget.ppipe_win)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.ppipe2_win)"></t></td> - </tr> - <tr class="table-legend-total"> - <td style="width: 20px;"></td> - <td>Total</td> - <td class="nb"><t t-esc="widget.render_percent(widget.total)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.total2)"></t></td> - </tr> - <tr> - <td style="width: 20px;"></td> - <td></td> - <td class="nb"></td> - <td class="nb"></td> - </tr> - <tr> - <td style="background-color: #F6ACA2; width: 20px;"></td> - <td>Pipe</td> - <td class="nb"><t t-esc="widget.render_percent(widget.ppipe_to_win)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.ppipe2_to_win)"></t></td> - </tr> - <tr> - <td style="background-color: #eee; width: 20px;"></td> - <td>To Do</td> - <td class="nb"><t t-esc="widget.render_percent(widget.ptarg)"></t></td> - <td class="nb"><t t-esc="widget.render_keur(widget.ptarg2)"></t></td> - </tr> - </table> - </div> - </div> - </div> - </div> - <!-- COLONNE 3 --> - <div class="col-xs-12 col-sm-6 col-md-4 tresorerie"> - <h3>Trésorerie</h3> - <!-- Tréso --> - <div class="col-xs-12"> - <div class="card"> - <div class="card-body"> - <h5 class="card-title">Trésorerie</h5> - <p class="card-maj">Denière mise à jour le <t t-esc="widget.render_date(widget.values.date_maj)"></t></p> - <p class="card-number"> - <a id="releve"> - <strong><t t-esc="widget.render_monetary(widget.values.tresorerie)"></t></strong> - </a> - </p> - </div> - </div> - </div> - <!-- Non encaissé / Du --> - <div class="col-xs-12 dashboard-tab"> - <ul class="nav nav-tabs" id="tab3"> - <li class="nav-item"> - <a class="nav-link active" data-toggle="tab" href="#non_encaisse">Facturé non encaissé</a> - </li> - <li class="nav-item"> - <a class="nav-link" data-toggle="tab" href="#fournisseur">Fournisseurs</a> - </li> - </ul> - <div class="tab-content card-tab" id="myTab3Content"> - <div id="non_encaisse" class="tab-pane fade show active in"> - <p class="card-number"> - <a id="facture_non_encaisse"> - <t t-esc="widget.render_monetary(widget.values.a_encaisser)"></t> - </a> - </p> - </div> - <div id="fournisseur" class="tab-pane fade"> - <p class="card-number"> - <a id="fournisseur_link"> - <t t-esc="widget.render_monetary(widget.values.a_payer)"></t> - </a> - </p> - </div> - </div> - </div> - <!-- Variation --> - <div class="col-xs-12 dashboard-tab"> - <ul class="nav nav-tabs" id="myTab2"> - <li class="nav-item"> - <a class="nav-link active" data-toggle="tab" href="#variation">Variation</a> - </li> - <li class="nav-item"> - <a class="nav-link" data-toggle="tab" href="#e_s">Entrées/Sorties</a> - </li> - </ul> - <div class="tab-content card-tab" id="myTab2Content"> - <div id="variation" class="tab-pane fade show active in"> - <p class="card-number"> - <t t-raw="widget.render_monetary_color(widget.values.variation)"></t> - </p> - </div> - <div id="e_s" class="tab-pane fade"> - <div class="card-half"> - <h5 class="card-title">Encaissé</h5> - <p class="card-number"> - <t t-esc="widget.render_monetary(widget.values.entree)"></t> - </p> - </div> - <div class="card-half"> - <h5 class="card-title">Sorties</h5> - <p class="card-number"> - <t t-esc="widget.render_monetary(widget.values.sortie)"></t> - </p> - </div> - <div class="clearfix"></div> - </div> - </div> - </div> - <!-- <div class="col-xs-12"> - <div class="card card-cca"> - <div class="card-body"> - <div class="card-cca-half"> - <h5 class="card-title">CCA en cours</h5> - <p class="card-number"> - <t t-raw="widget.render_monetary(widget.values.cca)"></t> - </p> - </div> - <div class="card-cca-half"> - <h5 class="card-title">Capital Social</h5> - <p class="card-number"> - <t t-raw="widget.render_monetary(widget.values.capital)"></t> - </p> - </div> - </div> - </div> - </div> --> - </div> - </div> - </div> - </t> - -</templates> diff --git a/templates/invoice_allocation_templates.xml b/templates/invoice_allocation_templates.xml index 6b73730..c0b955a 100644 --- a/templates/invoice_allocation_templates.xml +++ b/templates/invoice_allocation_templates.xml @@ -104,7 +104,7 @@ data-input-name="employee" min="0" max="100" - t-att-value="20 if p.id == 1 else i.get_employee_allocation(p)" + t-att-value="i.get_employee_allocation(p)" /> </div> </t> diff --git a/views/account_invoice_employee_assign.xml b/views/account_invoice_employee_assign.xml new file mode 100644 index 0000000..38f0f5b --- /dev/null +++ b/views/account_invoice_employee_assign.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" ?> +<!-- Copyright 2022 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> +<odoo> + <data> + <!-- Form --> + <record id="legicoop_invoice_employee_assign_form" model="ir.ui.view"> + <field name="name">legicoop.account.invoice.employee.assign.form</field> + <field name="model">account.invoice.employee.assign</field> + <field name="arch" type="xml"> + <form string="Assignation CA employés"> + <sheet> + <group> + <group> + <field name="invoice_id" readonly="1" /> + <field name="partner_id" /> + <field name="percentage" /> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <!-- Tree view --> + <record id="legicoop_invoice_employee_assign_tree" model="ir.ui.view"> + <field name="name">legicoop.account.invoice.employee.assign.tree</field> + <field name="model">account.invoice.employee.assign</field> + <field name="arch" type="xml"> + <tree string="Assignation CA employés"> + <field name="invoice_id" readonly="1" /> + <field name="partner_id" /> + <field name="percentage" /> + </tree> + </field> + </record> + + <!-- Search view --> + <record id="legicoop_invoice_employee_assign_search" model="ir.ui.view"> + <field name="name">legicoop.account.invoice.employee.assign.search</field> + <field name="model">account.invoice.employee.assign</field> + <field name="arch" type="xml"> + <search string="Assignation CA employés"> + <field name="invoice_id" /> + <field name="partner_id" /> + <group expand="0" name="group_by" string="Group By"> + <filter string="Facture" name="group_invoice" context="{'group_by':'invoice_id'}" /> + <filter string="Employé" name="group_employee" context="{'group_by':'partner_id'}" /> + </group> + </search> + </field> + </record> + + <!-- Action --> + <record id="legicoop_invoice_employee_assign_action" model="ir.actions.act_window"> + <field name="name">Assignation CA employés</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">account.invoice.employee.assign</field> + <field name="view_mode">tree,pivot,form</field> + </record> + + </data> +</odoo> diff --git a/views/menus.xml b/views/menus.xml index 49ce95b..d755478 100644 --- a/views/menus.xml +++ b/views/menus.xml @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <odoo> <data> - - <!-- This Menu Item must have a parent and an action --> + <!-- Qweb Assignation --> <menuitem id="account_invoice_allocation_menu" name="Affecter la répartition des factures" @@ -10,6 +9,14 @@ action="account_invoice_invoice_allocation" sequence="80" /> + <!-- Configuration --> + <menuitem + id="account_invoice_allocation_menu" + name="Répartition des factures" + parent="account.menu_analytic_accounting" + action="legicoop_invoice_employee_assign_action" + sequence="80" + /> </data> </odoo> -- GitLab