From 2265d175ab949dcffd4772e433b30a6d7d9270c1 Mon Sep 17 00:00:00 2001 From: Parthiv Patel Date: Fri, 4 Mar 2022 08:35:54 +0000 Subject: [PATCH] [PATCH] Upstream patch - 04032022 --- addons/account/views/account_move_views.xml | 2 +- .../account_edi_proxy_client/__manifest__.py | 2 - .../models/account_edi_proxy_user.py | 2 +- addons/hr/views/res_users.xml | 4 +- .../demo/account_customer_refund_demo.xml | 3 + addons/l10n_ar/models/account_move.py | 2 +- addons/l10n_cl/models/account_move.py | 2 +- .../models/res_config_settings.py | 68 +++++++++++++++++-- .../views/res_config_settings_views.xml | 47 ++++++------- .../js/Screens/PaymentScreen/PaymentScreen.js | 15 ++-- addons/point_of_sale/static/src/js/models.js | 24 ++++--- addons/pos_six/static/src/js/payment_six.js | 13 ++++ addons/purchase/models/account_invoice.py | 1 - addons/purchase/models/purchase.py | 3 +- .../purchase/tests/test_purchase_invoice.py | 68 +++++++++++++++++++ addons/sale/views/sale_views.xml | 3 - 16 files changed, 198 insertions(+), 61 deletions(-) diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 4624bb91d5..7796bdd4b8 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -890,7 +890,7 @@ - + diff --git a/addons/account_edi_proxy_client/__manifest__.py b/addons/account_edi_proxy_client/__manifest__.py index 293d80c094..89ab98dbeb 100644 --- a/addons/account_edi_proxy_client/__manifest__.py +++ b/addons/account_edi_proxy_client/__manifest__.py @@ -17,8 +17,6 @@ Flectra database. }, 'data': [ 'security/ir.model.access.csv', - ], - 'demo': [ 'data/config_demo.xml', ], 'installable': True, diff --git a/addons/account_edi_proxy_client/models/account_edi_proxy_user.py b/addons/account_edi_proxy_client/models/account_edi_proxy_user.py index badd24cbec..c3e5e242b1 100644 --- a/addons/account_edi_proxy_client/models/account_edi_proxy_user.py +++ b/addons/account_edi_proxy_client/models/account_edi_proxy_user.py @@ -137,7 +137,7 @@ class AccountEdiProxyClientUser(models.Model): ) if self._get_demo_state() == 'demo': # simulate registration - response = {'id_client': 'demo', 'refresh_token': 'demo'} + response = {'id_client': f'demo{company.id}', 'refresh_token': 'demo'} else: try: # b64encode returns a bytestring, we need it as a string diff --git a/addons/hr/views/res_users.xml b/addons/hr/views/res_users.xml index 7c2826aaf2..deb53bb284 100644 --- a/addons/hr/views/res_users.xml +++ b/addons/hr/views/res_users.xml @@ -12,9 +12,9 @@ primary -
+ 1 -
+

diff --git a/addons/l10n_ar/demo/account_customer_refund_demo.xml b/addons/l10n_ar/demo/account_customer_refund_demo.xml index a6b4796f64..14d32b5ad3 100644 --- a/addons/l10n_ar/demo/account_customer_refund_demo.xml +++ b/addons/l10n_ar/demo/account_customer_refund_demo.xml @@ -6,6 +6,7 @@ Mercadería defectuosa refund + @@ -16,6 +17,7 @@ Venta cancelada cancel + @@ -26,6 +28,7 @@ Venta cancelada cancel + diff --git a/addons/l10n_ar/models/account_move.py b/addons/l10n_ar/models/account_move.py index 7b2eecc304..b77091d20a 100644 --- a/addons/l10n_ar/models/account_move.py +++ b/addons/l10n_ar/models/account_move.py @@ -222,7 +222,7 @@ class AccountMove(models.Model): def _get_starting_sequence(self): """ If use documents then will create a new starting sequence using the document type code prefix and the journal document number with a 8 padding number """ - if self.journal_id.l10n_latam_use_documents and self.env.company.country_id.code == "AR": + if self.journal_id.l10n_latam_use_documents and self.company_id.country_id.code == "AR": if self.l10n_latam_document_type_id: return self._get_formatted_sequence() return super()._get_starting_sequence() diff --git a/addons/l10n_cl/models/account_move.py b/addons/l10n_cl/models/account_move.py index 1263395f6c..0349fbfaf2 100644 --- a/addons/l10n_cl/models/account_move.py +++ b/addons/l10n_cl/models/account_move.py @@ -100,7 +100,7 @@ class AccountMove(models.Model): def _get_starting_sequence(self): """ If use documents then will create a new starting sequence using the document type code prefix and the journal document number with a 6 padding number """ - if self.journal_id.l10n_latam_use_documents and self.env.company.country_id.code == "CL": + if self.journal_id.l10n_latam_use_documents and self.company_id.country_id.code == "CL": if self.l10n_latam_document_type_id: return self._l10n_cl_get_formatted_sequence() return super()._get_starting_sequence() diff --git a/addons/l10n_it_edi_sdicoop/models/res_config_settings.py b/addons/l10n_it_edi_sdicoop/models/res_config_settings.py index 2bbbca4ddb..cb6b1c0e56 100644 --- a/addons/l10n_it_edi_sdicoop/models/res_config_settings.py +++ b/addons/l10n_it_edi_sdicoop/models/res_config_settings.py @@ -1,21 +1,28 @@ # -*- coding: utf-8 -*- -from flectra import api, models, fields - +from flectra import api, models, fields, _ +from flectra.exceptions import UserError class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' is_edi_proxy_active = fields.Boolean(compute='_compute_is_edi_proxy_active') + l10n_it_edi_proxy_current_state = fields.Char(compute='_compute_l10n_it_edi_proxy_current_state') + l10n_it_edi_sdicoop_register = fields.Boolean(compute='_compute_l10n_it_edi_sdicoop_register', inverse='_set_l10n_it_edi_sdicoop_register_demo_mode') l10n_it_edi_sdicoop_demo_mode = fields.Selection( [('demo', 'Demo'), ('test', 'Test (experimental)'), ('prod', 'Official')], compute='_compute_l10n_it_edi_sdicoop_demo_mode', - inverse='_set_l10n_it_edi_sdicoop_demo_mode', + inverse='_set_l10n_it_edi_sdicoop_register_demo_mode', readonly=False) - @api.depends("is_edi_proxy_active") + def _create_proxy_user(self, company_id): + fattura_pa = self.env.ref('l10n_it_edi.edi_fatturaPA') + edi_identification = fattura_pa._get_proxy_identification(company_id) + self.env['account_edi_proxy_client.user']._register_proxy_user(company_id, fattura_pa, edi_identification) + + @api.depends('company_id.account_edi_proxy_client_ids', 'company_id.account_edi_proxy_client_ids.active') def _compute_l10n_it_edi_sdicoop_demo_mode(self): for config in self: config.l10n_it_edi_sdicoop_demo_mode = self.env['account_edi_proxy_client.user']._get_demo_state() @@ -29,6 +36,22 @@ class ResConfigSettings(models.TransientModel): for config in self: config.is_edi_proxy_active = config.company_id.account_edi_proxy_client_ids + @api.depends('company_id.account_edi_proxy_client_ids', 'company_id.account_edi_proxy_client_ids.active') + def _compute_l10n_it_edi_proxy_current_state(self): + fattura_pa = self.env.ref('l10n_it_edi.edi_fatturaPA') + for config in self: + proxy_user = config.company_id.account_edi_proxy_client_ids.search([ + ('company_id', '=', config.company_id.id), + ('edi_format_id','=', fattura_pa.id), + ], limit=1) + + config.l10n_it_edi_proxy_current_state = 'inactive' if not proxy_user else 'demo' if proxy_user.id_client[:4] == 'demo' else 'active' + + @api.depends('company_id') + def _compute_l10n_it_edi_sdicoop_register(self): + """Needed because it expects a compute""" + self.l10n_it_edi_sdicoop_register = False + def button_create_proxy_user(self): # For now, only fattura_pa uses the proxy. # To use it for more, we have to either make the activation of the proxy on a format basis @@ -39,3 +62,40 @@ class ResConfigSettings(models.TransientModel): return self.env['account_edi_proxy_client.user']._register_proxy_user(self.company_id, fattura_pa, edi_identification) + + def _set_l10n_it_edi_sdicoop_register_demo_mode(self): + + fattura_pa = self.env.ref('l10n_it_edi.edi_fatturaPA') + for config in self: + + proxy_user = self.env['account_edi_proxy_client.user'].search([ + ('company_id', '=', config.company_id.id), + ('edi_format_id', '=', fattura_pa.id) + ], limit=1) + + real_proxy_users = self.env['account_edi_proxy_client.user'].sudo().search([ + ('id_client', 'not like', 'demo'), + ]) + + # Update the config as per the selected radio button + previous_demo_state = proxy_user._get_demo_state() + self.env['ir.config_parameter'].set_param('account_edi_proxy_client.demo', config.l10n_it_edi_sdicoop_demo_mode) + + # If the user is trying to change from a state in which they have a registered official or testing proxy client + # to another state, we should stop them + if real_proxy_users and previous_demo_state != config.l10n_it_edi_sdicoop_demo_mode: + raise UserError(_("The company has already registered with the service as 'Test' or 'Official', it cannot change.")) + + + if config.l10n_it_edi_sdicoop_register: + # There should only be one user at a time, if there are no users, register one + if not proxy_user: + self._create_proxy_user(config.company_id) + return + + # If there is a demo user, and we are transitioning from demo to test or production, we should + # delete all demo users and then create the new user. + elif proxy_user.id_client[:4] == 'demo' and config.l10n_it_edi_sdicoop_demo_mode != 'demo': + self.env['account_edi_proxy_client.user'].search([('id_client', '=like', 'demo%')]).sudo().unlink() + self._create_proxy_user(config.company_id) + diff --git a/addons/l10n_it_edi_sdicoop/views/res_config_settings_views.xml b/addons/l10n_it_edi_sdicoop/views/res_config_settings_views.xml index a51092cc30..83060cc085 100644 --- a/addons/l10n_it_edi_sdicoop/views/res_config_settings_views.xml +++ b/addons/l10n_it_edi_sdicoop/views/res_config_settings_views.xml @@ -12,44 +12,37 @@
- Allow Flectra to process invoices -
- By clicking this button, I accept that Flectra may process my invoices. -
-
- -
-
-
-
-
-
-
-
-
-
+
+ Fattura Elettronica mode
In demo mode Flectra will just simulate the sending of invoices to the government.
In test mode (experimental) Flectra will send the invoices to a non-production service. + Saving this change will direct all companies on this database to this use this configuration. + Once registered for testing or official, the mode cannot be changed.
+
+ Allow Flectra to process invoices +
+ By checking this box, I accept that Flectra may process my invoices. +
+
+ +
+ +
+
+ An Official or Test service has been registered. +
+
+ A Demo service is in use. +
diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js index 61e04ecb4b..edfaded4e2 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js @@ -58,20 +58,17 @@ flectra.define('point_of_sale.PaymentScreen', function (require) { } addNewPaymentLine({ detail: paymentMethod }) { // original function: click_paymentmethods - if (this.currentOrder.electronic_payment_in_progress()) { + let result = this.currentOrder.add_paymentline(paymentMethod); + if (result){ + NumberBuffer.reset(); + return true; + } + else{ this.showPopup('ErrorPopup', { title: this.env._t('Error'), body: this.env._t('There is already an electronic payment in progress.'), }); return false; - } else { - this.currentOrder.add_paymentline(paymentMethod); - NumberBuffer.reset(); - this.payment_interface = paymentMethod.payment_terminal; - if (this.payment_interface) { - this.currentOrder.selected_paymentline.set_payment_status('pending'); - } - return true; } } _updateSelectedPaymentline() { diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 9a1ae38a09..6d396aafbb 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -3101,15 +3101,23 @@ exports.Order = Backbone.Model.extend({ /* ---- Payment Lines --- */ add_paymentline: function(payment_method) { this.assert_editable(); - var newPaymentline = new exports.Paymentline({},{order: this, payment_method:payment_method, pos: this.pos}); - newPaymentline.set_amount(this.get_due()); - this.paymentlines.add(newPaymentline); - this.select_paymentline(newPaymentline); - if(this.pos.config.cash_rounding){ - this.selected_paymentline.set_amount(0); - this.selected_paymentline.set_amount(this.get_due()); + if (this.electronic_payment_in_progress()) { + return false; + } else { + var newPaymentline = new exports.Paymentline({},{order: this, payment_method:payment_method, pos: this.pos}); + newPaymentline.set_amount(this.get_due()); + this.paymentlines.add(newPaymentline); + this.select_paymentline(newPaymentline); + if(this.pos.config.cash_rounding){ + this.selected_paymentline.set_amount(0); + this.selected_paymentline.set_amount(this.get_due()); + } + + if (payment_method.payment_terminal) { + newPaymentline.set_payment_status('pending'); + } + return newPaymentline; } - return newPaymentline; }, get_paymentlines: function(){ return this.paymentlines.models; diff --git a/addons/pos_six/static/src/js/payment_six.js b/addons/pos_six/static/src/js/payment_six.js index 01371b03d4..69d97ec05d 100644 --- a/addons/pos_six/static/src/js/payment_six.js +++ b/addons/pos_six/static/src/js/payment_six.js @@ -28,6 +28,19 @@ var PaymentSix = PaymentInterface.extend({ this._super.apply(this, arguments); this.enable_reversals(); + var terminal_ip = this.payment_method.six_terminal_ip; + var instanced_payment_method = _.find(this.pos.payment_methods, function(payment_method) { + return payment_method.use_payment_terminal === "six" + && payment_method.six_terminal_ip === terminal_ip + && payment_method.payment_terminal + }) + if (instanced_payment_method !== undefined) { + var payment_terminal = instanced_payment_method.payment_terminal; + this.terminal = payment_terminal.terminal; + this.terminalListener = payment_terminal.terminalListener; + return; + } + var settings = new timapi.TerminalSettings(); settings.connectionMode = timapi.constants.ConnectionMode.onFixIp; settings.connectionIPString = this.payment_method.six_terminal_ip; diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 77df9703e7..a08370ae06 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -73,7 +73,6 @@ class AccountMove(models.Model): self.purchase_id = False self._onchange_currency() - self.partner_bank_id = self.bank_partner_id.bank_ids and self.bank_partner_id.bank_ids[0] @api.onchange('partner_id', 'company_id') def _onchange_partner_id(self): diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 4f270a2161..2a26accc2d 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -547,6 +547,7 @@ class PurchaseOrder(models.Model): raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice'] + partner_bank_id = self.partner_id.bank_ids.filtered_domain(['|', ('company_id', '=', False), ('company_id', '=', self.company_id.id)])[:1] invoice_vals = { 'ref': self.partner_ref or '', 'move_type': move_type, @@ -556,7 +557,7 @@ class PurchaseOrder(models.Model): 'partner_id': partner_invoice_id, 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(partner_invoice_id)).id, 'payment_reference': self.partner_ref or '', - 'partner_bank_id': self.partner_id.bank_ids[:1].id, + 'partner_bank_id': partner_bank_id.id, 'invoice_origin': self.name, 'invoice_payment_term_id': self.payment_term_id.id, 'invoice_line_ids': [], diff --git a/addons/purchase/tests/test_purchase_invoice.py b/addons/purchase/tests/test_purchase_invoice.py index 55d26b2dbe..6faf43b927 100644 --- a/addons/purchase/tests/test_purchase_invoice.py +++ b/addons/purchase/tests/test_purchase_invoice.py @@ -327,3 +327,71 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon): aml = self.env['account.move.line'].search([('purchase_line_id', '=', purchase_order.order_line.id)]) self.assertRecordValues(aml, [{'analytic_account_id': analytic_account_manual.id}]) + + def test_multicompany_partner_bank(self): + """ Test that in a multiple company environment, the bank account of the invoice + is the one corresponding to the active company. """ + company_a = self.env.user.company_id + company_b = self.env['res.company'].create({ + 'name': 'Company B', + }) + self.env.ref('l10n_generic_coa.configurable_chart_template')._load(15.0, 15.0, company_b) + + partner = self.env['res.partner'].create({ + 'name': 'AAAAA', + }) + partner_bank_a = self.env['res.partner.bank'].create({ + 'acc_number': "BE01 23456789 10", + 'partner_id': partner.id, + 'company_id': company_a.id, + 'acc_type': 'bank' + }) + partner_bank_b = self.env['res.partner.bank'].create({ + 'acc_number': "BE10 98765432 10", + 'partner_id': partner.id, + 'company_id': company_b.id, + 'acc_type': 'bank' + }) + partner.bank_ids = [partner_bank_a.id, partner_bank_b.id] + + PurchaseOrder = self.env['purchase.order'].with_context(tracking_disable=True) + po_a = PurchaseOrder.with_company(company_a).create({ + 'partner_id': partner.id, + 'company_id': company_a.id, + 'currency_id': company_a.currency_id.id, + 'date_order': '2019-01-01', + }) + po_b = PurchaseOrder.with_company(company_b).create({ + 'partner_id': partner.id, + 'company_id': company_b.id, + 'currency_id': company_b.currency_id.id, + 'date_order': '2019-01-01', + }) + + vals_pol = { + 'name': self.product_deliver.name, + 'product_id': self.product_deliver.id, + 'product_qty': 10.0, + 'product_uom': self.product_deliver.uom_id.id, + 'price_unit': self.product_deliver.list_price, + 'order_id': po_a.id, + 'taxes_id': False, + } + PurchaseOrderLine = self.env['purchase.order.line'].with_context(tracking_disable=True) + PurchaseOrderLine.create(vals_pol) + vals_pol['order_id'] = po_b.id + PurchaseOrderLine.create(vals_pol) + + po_a.button_confirm() + po_b.button_confirm() + + po_a.order_line.qty_received = po_b.order_line.qty_received = 10 + + po_a.with_company(company_a).action_create_invoice() + po_b.with_company(company_b).action_create_invoice() + + self.assertEqual(po_a.invoice_ids.company_id, company_a) + self.assertEqual(po_a.invoice_ids.partner_bank_id, partner_bank_a) + + self.assertEqual(po_b.invoice_ids.company_id, company_b) + self.assertEqual(po_b.invoice_ids.partner_bank_id, partner_bank_b) diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml index 122bf5fe30..9d9f2dd28a 100644 --- a/addons/sale/views/sale_views.xml +++ b/addons/sale/views/sale_views.xml @@ -1215,9 +1215,6 @@ groups="sale.group_delivery_invoice_address" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'out_receipt'))]}"/> - - product.group_discount_per_so_line -