[PATCH] Upstream patch - 04032022

This commit is contained in:
Parthiv Patel committed 2022-03-04 08:35:54 +00:00
1 parent 57046d9c04
commit 2265d175ab
16 files changed
+198 -61

No files matched your search

+1 -1
View File
@@ -890,7 +890,7 @@
<field name="quantity"/>
<field name="product_uom_id" groups="uom.group_uom"/>
<field name="price_unit"/>
<field name="discount" groups="product.group_discount_per_so_line"/>
<field name="discount" string="Disc.%"/>
<field name="currency_id" invisible="1"/>
</group>
<group>
@@ -17,8 +17,6 @@ Flectra database.
},
'data': [
'security/ir.model.access.csv',
],
'demo': [
'data/config_demo.xml',
],
'installable': True,
@@ -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
+2 -2
View File
@@ -12,9 +12,9 @@
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<footer position="attributes">
<xpath expr="//footer[not(ancestor::field)]" position="attributes">
<attribute name="invisible">1</attribute>
</footer>
</xpath>
<h1 position="replace"/>
<xpath expr="//field[@name='image_1920']" position="replace"/>
<xpath expr="//field[@name='company_id']" position="attributes">
@@ -6,6 +6,7 @@
<field name="reason">Mercadería defectuosa</field>
<field name="refund_method">refund</field>
<field name="move_ids" eval="[(4, ref('demo_invoice_3'), 0)]"/>
<field name="journal_id" model="account.move.reversal" eval="obj().env.ref('l10n_ar.demo_invoice_3').journal_id"/>
<field name="date" eval="time.strftime('%Y-%m')+'-01'"/>
</record>
@@ -16,6 +17,7 @@
<field name="reason">Venta cancelada</field>
<field name="refund_method">cancel</field>
<field name="move_ids" eval="[(4, ref('demo_invoice_4'), 0)]"/>
<field name="journal_id" model="account.move.reversal" eval="obj().env.ref('l10n_ar.demo_invoice_4').journal_id"/>
<field name="date" eval="time.strftime('%Y-%m')+'-01'"/>
</record>
@@ -26,6 +28,7 @@
<field name="reason">Venta cancelada</field>
<field name="refund_method">cancel</field>
<field name="move_ids" eval="[(4, ref('demo_invoice_16'), 0)]"/>
<field name="journal_id" model="account.move.reversal" eval="obj().env.ref('l10n_ar.demo_invoice_16').journal_id"/>
<field name="date" eval="time.strftime('%Y-%m')+'-01'"/>
</record>
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -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()
@@ -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)
@@ -12,44 +12,37 @@
<div class="row mt16 o_settings_container" id='account_edi'>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">Allow Flectra to process invoices</span>
<div class="text-muted">
By clicking this button, I accept that Flectra may process my invoices.
</div>
<div class="content-group">
<field name="is_edi_proxy_active" invisible="True" />
<div class="row mt8">
<div class="col-lg-6" title="Register">
<button name="button_create_proxy_user"
type="object"
string="Register"
class="btn-primary" icon="fa-lg fa-check"
attrs="{'invisible':[('is_edi_proxy_active', '=', True)]}"/>
<button name="button_create_proxy_user"
type="object"
string="Already registered"
disabled="1"
class="btn-lnk" icon="fa-lg fa-check"
attrs="{'invisible':[('is_edi_proxy_active', '=', False)]}"/>
</div>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<div class="content-group">
<div class="group-content">
<field name="l10n_it_edi_proxy_current_state" invisible="1"/>
<span class="o_form_label">
Fattura Elettronica mode
</span>
<div class="text-muted">
In demo mode Flectra will just simulate the sending of invoices to the government.<br/>
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.
</div>
<field name="l10n_it_edi_sdicoop_demo_mode"
widget="radio"
options="{'horizontal': true}"/>
</div>
<div class="mt8 content-group" attrs="{'invisible': ['|',('l10n_it_edi_proxy_current_state','=','active'), '&amp;', ('l10n_it_edi_proxy_current_state','=','demo'), ('l10n_it_edi_sdicoop_demo_mode','=','demo')]}">
<span class="o_form_label">Allow Flectra to process invoices</span>
<div class="text-muted">
By checking this box, I accept that Flectra may process my invoices.
</div>
<div class="content-group">
<field name="l10n_it_edi_sdicoop_register"/>
</div>
</div>
<div class="text-success mt8" attrs="{'invisible': [('l10n_it_edi_proxy_current_state','in', ['inactive', 'demo'])]}">
An Official or Test service has been registered.
</div>
<div class="text-success mt8" attrs="{'invisible': ['|',('l10n_it_edi_proxy_current_state','!=', 'demo'), ('l10n_it_edi_sdicoop_demo_mode', '!=', 'demo')]}">
A Demo service is in use.
</div>
</div>
</div>
</div>
@@ -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() {
+16 -8
View File
@@ -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;
@@ -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;
@@ -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):
+2 -1
View File
@@ -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': [],
@@ -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)
-3
View File
@@ -1215,9 +1215,6 @@
groups="sale.group_delivery_invoice_address"
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'out_receipt'))]}"/>
</xpath>
<xpath expr="//field[@name='invoice_line_ids']//field[@name='discount']" position="attributes">
<attribute name="groups">product.group_discount_per_so_line</attribute>
</xpath>
<xpath expr="//group[@name='sale_info_group']/field[@name='invoice_user_id']" position="after">
<field name="team_id" kanban_view_ref="%(sales_team.crm_team_view_kanban)s"/>
</xpath>