diff --git a/controllers/main.py b/controllers/main.py index d3b2497e2202c09a30259ebd1e4424dc293acc3f..42a78666032c7973dfb9fcf9844a3a134861bb42 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -7,23 +7,25 @@ from odoo.http import request class AccountInvoiceAllocationController(http.Controller): - - @http.route('/account/allocation', type='json', auth="user") + @http.route("/account/allocation", type="json", auth="user") def plan(self, domain): """ Get the HTML of the account invoice for invoice allocation the given domain :param domain: a domain for account.invoice """ - 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") + 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") view = request.env.ref("legicoop_account.invoice_allocation") return { - 'html_content': view.render({ - "invoice_ids": invoice_ids, - "partner_ids": partner_ids, - }), + "html_content": view.render( + { + "invoice_ids": invoice_ids, + "partner_ids": partner_ids, + } + ), "invoice_ids": invoice_ids.ids, } diff --git a/models/account_invoice.py b/models/account_invoice.py index a5ae05538bede7eea734354d82e7d2fff26a584d..db70cc1f93ce4da9bd440be2d6c737b4398f9828 100644 --- a/models/account_invoice.py +++ b/models/account_invoice.py @@ -33,7 +33,11 @@ class AccountInvoice(models.Model): store=True, default=False, ) - suspicious_client = fields.Boolean("Client douteux", default=False, tracking=True,) + suspicious_client = fields.Boolean( + "Client douteux", + default=False, + tracking=True, + ) # ------------------------------------------------------ # Computed field diff --git a/models/account_invoice_employee_assign.py b/models/account_invoice_employee_assign.py index 14ecb08b1ecdac680b983e98d547e21bbc9c051c..3da7d76f02184e8510e1a8501f3d6a712b14cc07 100644 --- a/models/account_invoice_employee_assign.py +++ b/models/account_invoice_employee_assign.py @@ -48,7 +48,9 @@ class AccountInvoiceEmployeeAssign(models.Model): for val in vals: message += ( self.env["res.partner"].browse(val.get("partner_id")).name - + " - " + val.get("percent") + "%" + + " - " + + val.get("percent") + + "%" ) res.invoice_id.message_post(message) return res @@ -61,7 +63,9 @@ class AccountInvoiceEmployeeAssign(models.Model): message = "<strong>Affectation</strong> | Création ligne d'affectation : " message += ( self.env["res.partner"].browse(vals.get("partner_id")).name - + " - " + str(vals.get("percentage")) + "%" + + " - " + + str(vals.get("percentage")) + + "%" ) res.invoice_id.message_post(body=message) return res @@ -71,7 +75,10 @@ class AccountInvoiceEmployeeAssign(models.Model): for line in self: message = ( "<strong>Affectation</strong> | Modification de la ligne : " - + line.partner_id.name + " - " + str(line.percentage) + "%" + + line.partner_id.name + + " - " + + str(line.percentage) + + "%" ) line.invoice_id.message_post(body=message) result = super(AccountInvoiceEmployeeAssign, self).write(vals) @@ -82,7 +89,10 @@ class AccountInvoiceEmployeeAssign(models.Model): for line in self: message = ( "<strong>Affectation</strong> | Suppression de la ligne : " - + line.partner_id.name + " - " + str(line.percentage) + "%" + + line.partner_id.name + + " - " + + str(line.percentage) + + "%" ) line.invoice_id.message_post(body=message) return super(AccountInvoiceEmployeeAssign, self).unlink() diff --git a/models/product.py b/models/product.py index e3a47c45b683f9cdb7b2a06fb622e04feab9e183..bc440b1b2c628f6bc928f1f94fae3ef0b1037fdf 100644 --- a/models/product.py +++ b/models/product.py @@ -5,7 +5,7 @@ from odoo import fields, models class ProductTemplate(models.Model): - _inherit = 'product.template' + _inherit = "product.template" default_code = fields.Char(track_visibility=True) description_sale = fields.Text(track_visibility=True) diff --git a/static/src/css/invoice_allocation.css b/static/src/css/invoice_allocation.css index ca16dfb20e6a1ba6868698ec8ed6f13022db090e..e0fdd50bf5a0da560424c8fafdb4b805e6222d3f 100755 --- a/static/src/css/invoice_allocation.css +++ b/static/src/css/invoice_allocation.css @@ -6,7 +6,7 @@ } .allocation-title > div { padding: 5px 10px; - display:inline-block; + display: inline-block; } .allocation-content { padding-top: 70px; @@ -19,22 +19,22 @@ scrollbar-width: none; } .allocation-line-success { - background-color: rgba(40, 167, 69, 0.1) !important + background-color: rgba(40, 167, 69, 0.1) !important; } .allocation-line-danger { - background-color: rgba(220, 53, 69, 0.1) !important + background-color: rgba(220, 53, 69, 0.1) !important; } .allocation-line::-webkit-scrollbar { - height: 4px; + height: 4px; } .allocation-line::-webkit-scrollbar-track { - background: #eee; + background: #eee; } .allocation-line::-webkit-scrollbar-thumb { - background-color: #7C7BAD; - border-radius: 0px; + background-color: #7c7bad; + border-radius: 0px; } .allocation-col { diff --git a/static/src/js/invoice_allocation.js b/static/src/js/invoice_allocation.js index 9c1979a95b9776b2737cf651fbc05d70e70f5883..1cc94a710527ae1e9c51fff44018ea9222938c4d 100755 --- a/static/src/js/invoice_allocation.js +++ b/static/src/js/invoice_allocation.js @@ -1,15 +1,15 @@ // © 2019 Le Filament (<http://www.le-filament.com>) // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -odoo.define('legicoop_account.invoice_allocation', function (require) { +odoo.define("legicoop_account.invoice_allocation", function (require) { "use strict"; - var AbstractAction = require('web.AbstractAction'); - var ControlPanelMixin = require('web.ControlPanelMixin'); - var SearchView = require('web.SearchView'); - var core = require('web.core'); - var data = require('web.data'); - var pyUtils = require('web.py_utils'); + var AbstractAction = require("web.AbstractAction"); + var ControlPanelMixin = require("web.ControlPanelMixin"); + var SearchView = require("web.SearchView"); + var core = require("web.core"); + var data = require("web.data"); + var pyUtils = require("web.py_utils"); var _t = core._t; var QWeb = core.qweb; @@ -21,11 +21,11 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { /** * @override */ - init: function (parent, action) { + init: function (parent, action) { this._super.apply(this, arguments); this.action = action; this.action_manager = parent; - this.set('title', action.name || _t('Factures à répartir')); + this.set("title", action.name || _t("Factures à répartir")); this.invoice_ids = []; }, /** @@ -33,12 +33,15 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { */ willStart: function () { var self = this; - var view_id = this.action && this.action.search_view_id && this.action.search_view_id[0]; - var def = this - .loadViews('account.invoice', this.action.context || {}, [[view_id, 'search']]) - .then(function (result) { - self.fields_view = result.search; - }); + var view_id = + this.action && + this.action.search_view_id && + this.action.search_view_id[0]; + var def = this.loadViews("account.invoice", this.action.context || {}, [ + [view_id, "search"], + ]).then(function (result) { + self.fields_view = result.search; + }); return $.when(this._super(), def); }, /** @@ -47,7 +50,7 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { start: function () { var self = this; - // find default search from context + // Find default search from context var search_defaults = {}; var context = this.action.context || []; _.each(context, function (value, key) { @@ -57,7 +60,7 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { } }); - // create searchview + // Create searchview var options = { $buttons: $("<div>"), action: this.action, @@ -65,23 +68,23 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { search_defaults: search_defaults, }; - var dataset = new data.DataSetSearch(this, 'account.invoice'); + var dataset = new data.DataSetSearch(this, "account.invoice"); this.searchview = new SearchView(this, dataset, this.fields_view, options); - this.searchview.on('search', this, this._onSearch); + this.searchview.on("search", this, this._onSearch); var def1 = this._super.apply(this, arguments); var def2 = this.searchview.appendTo($("<div>")).then(function () { self.$searchview_buttons = self.searchview.$buttons.contents(); }); - return $.when(def1, def2).then(function(){ + return $.when(def1, def2).then(function () { self.searchview.do_search(); }); }, - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- // Public - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- /** * @override @@ -95,15 +98,15 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { }); }, - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- // Private - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- /** * Refresh the DOM html * * @private - * @param {string|html} dom + * @param {String|html} dom */ _refreshAllocation: function (dom) { var $dom = $(dom); @@ -120,9 +123,9 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { _fetchAllocation: function (domain) { var self = this; return this._rpc({ - route:"/account/allocation", + route: "/account/allocation", params: {domain: domain}, - }).then(function(result) { + }).then(function (result) { self._refreshAllocation(result.html_content); self._updateControlPanel(); self.invoice_ids = result.invoice_ids; @@ -133,7 +136,6 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { * @private */ _updateControlPanel: function () { - this.update_control_panel({ cp_content: { $searchview: this.searchview.$el, @@ -143,10 +145,9 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { }); }, - - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- // Handlers - //-------------------------------------------------------------------------- + // -------------------------------------------------------------------------- /** * @@ -156,46 +157,54 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { _onSubmit: function (ev) { ev.preventDefault(); var self = this; - let invoice_id = parseInt(ev.target.id) - let elements = Array.from(ev.target.elements) + const invoice_id = parseInt(ev.target.id); + const elements = Array.from(ev.target.elements); // Get employees with percent > 0 & total percent - let employees = elements.filter(function (el) { - return el.dataset.inputName === "employee" && el.valueAsNumber > 0; + const employees = elements.filter(function (el) { + return el.dataset.inputName === "employee" && el.valueAsNumber > 0; }); - let employeeTotal = employees.reduce(function (accumulator, employee) { - return accumulator + employee.valueAsNumber; + const employeeTotal = employees.reduce(function (accumulator, employee) { + return accumulator + employee.valueAsNumber; }, 0); // Get Subcontracting amount - let subcontracting = elements.find(el => el.name === "subcontracting_amount"); + const subcontracting = elements.find( + (el) => el.name === "subcontracting_amount" + ); // Get Subcontracting amount - let expense = elements.find(el => el.name === "expense_amount"); + const expense = elements.find((el) => el.name === "expense_amount"); if (employeeTotal != 100) { - var msg = $(ev.target).find(".error-message") - msg.html("<div class='alert alert-danger mt16' role='alert'>Mise à jour impossible : le total des pourcentage n'est pas égal à 100.</div>") - return - } else { - var new_allocation = [] + var msg = $(ev.target).find(".error-message"); + msg.html( + "<div class='alert alert-danger mt16' role='alert'>Mise à jour impossible : le total des pourcentage n'est pas égal à 100.</div>" + ); + return; + } + var new_allocation = []; _.each(employees, function (emp) { - new_allocation.push([0, 0, { - "partner_id": parseInt(emp.dataset.partnerId), - "percentage": emp.valueAsNumber, - }]) + new_allocation.push([ + 0, + 0, + { + partner_id: parseInt(emp.dataset.partnerId), + percentage: emp.valueAsNumber, + }, + ]); }); var new_values = { - "subcontracting_amount": subcontracting.valueAsNumber, - "expense_amount": expense.valueAsNumber, - "employee_allocation_ids": new_allocation, - } + subcontracting_amount: subcontracting.valueAsNumber, + expense_amount: expense.valueAsNumber, + employee_allocation_ids: new_allocation, + }; this._rpc({ model: "account.invoice", method: "create_employee_lines", args: [[invoice_id], new_values], }).then(function (result) { -// self._fetchAllocation() - self.searchview.do_search(); + // Self._fetchAllocation() + self.searchview.do_search(); }); - } + }, /** * This client action has its own search view and already listen on it. If @@ -209,16 +218,18 @@ odoo.define('legicoop_account.invoice_allocation', function (require) { _onSearch: function (event) { event.stopPropagation(); var session = this.getSession(); - // group by are disabled, so we don't take care of them + // Group by are disabled, so we don't take care of them var result = pyUtils.eval_domains_and_contexts({ domains: event.data.domains, - contexts: [session.user_context].concat(event.data.contexts) + contexts: [session.user_context].concat(event.data.contexts), }); this._fetchAllocation(result.domain); }, }); - core.action_registry.add('legicoop_account.invoice_allocation', AccountInvoiceAllocation); + core.action_registry.add( + "legicoop_account.invoice_allocation", + AccountInvoiceAllocation + ); }); - diff --git a/templates/invoice_allocation_templates.xml b/templates/invoice_allocation_templates.xml index 5f803fa1872658444264dc0c6da5c5e2863085c7..6b7373098846e9eda2f115e99df014c3afd4aef8 100644 --- a/templates/invoice_allocation_templates.xml +++ b/templates/invoice_allocation_templates.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8" ?> <odoo> <template id="invoice_allocation" name="Invoice Allocation"> @@ -25,7 +25,9 @@ <div class="allocation-block"> <form name="allocation_form" method="post" t-att-id="i.id"> <div class="error-message" /> - <div t-att-class="'allocation-line allocation-line-success' if i.is_allocated else 'allocation-line allocation-line-danger' if i.is_allocation_error else 'allocation-line'"> + <div + t-att-class="'allocation-line allocation-line-success' if i.is_allocated else 'allocation-line allocation-line-danger' if i.is_allocation_error else 'allocation-line'" + > <!-- Invoice name --> <div class="allocation-col"> <strong><span t-field="i.number" /></strong> @@ -35,43 +37,60 @@ <!-- Invoice amount --> <div class="allocation-col"> <strong> - <span t-field="i.amount_untaxed_signed" t-options="{'widget': 'monetary'}" /> + <span + t-field="i.amount_untaxed_signed" + t-options="{'widget': 'monetary'}" + /> </strong> <br /> <t t-if="i.state == 'paid'"> - <span class="badge badge-pill badge-success">Payée</span> + <span + class="badge badge-pill badge-success" + >Payée</span> </t> <t t-elif="i.state == 'draft'"> - <span class="badge badge-pill badge-dark">Brouillon</span> + <span + class="badge badge-pill badge-dark" + >Brouillon</span> </t> <t t-elif="i.state == 'cancelled'"> - <span class="badge badge-pill badge-danger">Annulée</span> + <span + class="badge badge-pill badge-danger" + >Annulée</span> </t> <t t-else=""> - <span class="badge badge-pill badge-warning">Ouverte</span> + <span + class="badge badge-pill badge-warning" + >Ouverte</span> </t> </div> <!-- Subcontracting amount --> - <div class="allocation-col" style="background-color: #eee; border-left: 1px solid #aaa;"> + <div + class="allocation-col" + style="background-color: #eee; border-left: 1px solid #aaa;" + > <div style="min-height: 50px;"> Sous-traitance (HT) </div> <input - type="number" - t-att-value="i.subcontracting_amount" - name="subcontracting_amount" - /> + type="number" + t-att-value="i.subcontracting_amount" + name="subcontracting_amount" + /> </div> <!-- Expense amount --> - <div class="allocation-col" style="background-color: #eee; border-right: 1px solid #aaa;"> + <div + class="allocation-col" + style="background-color: #eee; border-right: 1px solid #aaa;" + > <div style="min-height: 50px;"> Frais (HT) </div> <input - type="number" - t-att-value="i.expense_amount" - name="expense_amount" - /> + type="number" + t-att-value="i.expense_amount" + name="expense_amount" + /> </div> <!-- Employee allocation --> <t t-foreach="partner_ids" t-as="p"> @@ -80,20 +99,24 @@ <span t-field="p.name" /> </div> <input - type="number" - t-att-data-partner-id="p.id" - data-input-name="employee" - min="0" - max="100" - t-att-value="20 if p.id == 1 else i.get_employee_allocation(p)" - /> + type="number" + t-att-data-partner-id="p.id" + data-input-name="employee" + min="0" + max="100" + t-att-value="20 if p.id == 1 else i.get_employee_allocation(p)" + /> </div> </t> <!-- Button --> <div class="allocation-col"> <div style="height: 45px;"> </div> - <button t-att-id="i.id" class="btn btn-info" type="submit">Affecter</button> + <button + t-att-id="i.id" + class="btn btn-info" + type="submit" + >Affecter</button> </div> </div> </form> @@ -108,7 +131,9 @@ <field name="name">Allocation facture</field> <field name="tag">legicoop_account.invoice_allocation</field> <field name="res_model">account.invoice</field> - <field name="context">{'search_default_assign_ok': 1, 'search_default_assign_error': 1, 'search_default_unpaid': 1, 'search_default_in_payment': 1, 'search_default_paid': 1,}</field> + <field + name="context" + >{'search_default_assign_ok': 1, 'search_default_assign_error': 1, 'search_default_unpaid': 1, 'search_default_in_payment': 1, 'search_default_paid': 1,}</field> </record> </odoo> diff --git a/views/account_invoice_views.xml b/views/account_invoice_views.xml index 036b2d02ca37fa3bf4cd7c8dc06f7886b90fdd38..b6db5c00a70138ec3d33f321b84f13194c115d63 100644 --- a/views/account_invoice_views.xml +++ b/views/account_invoice_views.xml @@ -25,8 +25,8 @@ <page name="employee_assign" string="Répartition par employé"> <group> <group> - <field name="subcontracting_amount"/> - <field name="expense_amount"/> + <field name="subcontracting_amount" /> + <field name="expense_amount" /> </group> </group> <field name="is_allocation_error" invisible="1" /> @@ -73,10 +73,7 @@ sum="Total HT" /> </xpath> - <xpath - expr="//field[@name='state']" - position="after" - > + <xpath expr="//field[@name='state']" position="after"> <field name="suspicious_client" widget="boolean_toggle" /> </xpath> </field> diff --git a/views/assets.xml b/views/assets.xml index f6076b15e9f5808fdb7b1c130b487356b9753ae8..16734d3e88e8c2f328b642b80a659c032907409c 100755 --- a/views/assets.xml +++ b/views/assets.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?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). --> <odoo> @@ -6,8 +6,14 @@ <template id="legicoop_account_assets_backend" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> - <link href="/legicoop_account/static/src/css/invoice_allocation.css" rel="stylesheet" /> - <script type="text/javascript" src="/legicoop_account/static/src/js/invoice_allocation.js"></script> + <link + href="/legicoop_account/static/src/css/invoice_allocation.css" + rel="stylesheet" + /> + <script + type="text/javascript" + src="/legicoop_account/static/src/js/invoice_allocation.js" + /> </xpath> </template> diff --git a/views/menus.xml b/views/menus.xml index 47d9062a8e598ddea4f27d80cf318c22b64ff617..49ce95ba2a68d1373ce95f5613deee27c52fc9cf 100644 --- a/views/menus.xml +++ b/views/menus.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8" ?> <odoo> <data>