mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-08-19 01:34:43 -05:00
[PATCH] Upstream patch - 18022022
This commit is contained in:
@@ -11,6 +11,9 @@ class TaxAdjustments(models.TransientModel):
|
||||
def _get_default_journal(self):
|
||||
return self.env['account.journal'].search([('type', '=', 'general')], limit=1).id
|
||||
|
||||
def _domain_tax_report(self):
|
||||
return [('tag_name', '!=', None), ('report_id.country_id', '=', self.env.company.account_tax_fiscal_country_id.id)]
|
||||
|
||||
reason = fields.Char(string='Justification', required=True)
|
||||
journal_id = fields.Many2one('account.journal', string='Journal', required=True, default=_get_default_journal, domain=[('type', '=', 'general')])
|
||||
date = fields.Date(required=True, default=fields.Date.context_today)
|
||||
@@ -20,11 +23,11 @@ class TaxAdjustments(models.TransientModel):
|
||||
domain="[('deprecated', '=', False), ('is_off_balance', '=', False)]")
|
||||
amount = fields.Monetary(currency_field='company_currency_id', required=True)
|
||||
adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", required=True)
|
||||
tax_report_line_id = fields.Many2one(string="Report Line", comodel_name='account.tax.report.line', required=True, help="The report line to make an adjustment for.")
|
||||
tax_report_line_id = fields.Many2one(string="Report Line", comodel_name='account.tax.report.line', required=True, help="The report line to make an adjustment for.",
|
||||
domain=_domain_tax_report)
|
||||
company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda x: x.env.company.currency_id)
|
||||
report_id = fields.Many2one(string="Report", related='tax_report_line_id.report_id')
|
||||
|
||||
|
||||
def create_move(self):
|
||||
move_line_vals = []
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</h1>
|
||||
<group>
|
||||
<field name="report_id" invisible="1"/>
|
||||
<field name="tax_report_line_id" widget="selection" domain="[('tag_name', '!=', None)]"/>
|
||||
<field name="tax_report_line_id" widget="selection"/>
|
||||
</group>
|
||||
<group>
|
||||
<group>
|
||||
|
||||
@@ -18,6 +18,7 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DEFAULT_SERVER_URL = 'https://l10n-it-edi.api.flectrahq.com'
|
||||
DEFAULT_TEST_SERVER_URL = 'https://iap-services-test-saas12-test-13-test-14-test-15.test.flectrahq.com'
|
||||
TIMEOUT = 30
|
||||
|
||||
|
||||
@@ -54,6 +55,13 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
('unique_edi_identification_per_format', 'unique(edi_identification, edi_format_id)', 'This edi identification is already assigned to a user'),
|
||||
]
|
||||
|
||||
def _get_demo_state(self):
|
||||
demo_state = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False)
|
||||
return 'prod' if demo_state in ['prod', False] else 'test' if demo_state == 'test' else 'demo'
|
||||
|
||||
def _get_server_url(self):
|
||||
return DEFAULT_TEST_SERVER_URL if self._get_demo_state() == 'test' else self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
|
||||
def _make_request(self, url, params=False):
|
||||
''' Make a request to proxy and handle the generic elements of the reponse (errors, new refresh token).
|
||||
'''
|
||||
@@ -64,7 +72,7 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
'id': uuid.uuid4().hex,
|
||||
}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
if self._get_demo_state() == 'demo':
|
||||
# Last barrier : in case the demo mode is not handled by the caller, we block access.
|
||||
raise Exception("Can't access the proxy in demo mode")
|
||||
|
||||
@@ -124,14 +132,13 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
)
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
if self._get_demo_state() == 'demo':
|
||||
# simulate registration
|
||||
response = {'id_client': 'demo', 'refresh_token': 'demo'}
|
||||
else:
|
||||
try:
|
||||
# b64encode returns a bytestring, we need it as a string
|
||||
server_url = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
response = self._make_request(server_url + '/iap/account_edi/1/create_user', params={
|
||||
response = self._make_request(self._get_server_url() + '/iap/account_edi/1/create_user', params={
|
||||
'dbuuid': company.env['ir.config_parameter'].get_param('database.uuid'),
|
||||
'company_id': company.id,
|
||||
'edi_format_code': edi_format.code,
|
||||
@@ -159,8 +166,7 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
that multiple database use the same credentials. When receiving an error for an expired refresh_token,
|
||||
This method makes a request to get a new refresh token.
|
||||
'''
|
||||
server_url = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
response = self._make_request(server_url + '/iap/account_edi/1/renew_token')
|
||||
response = self._make_request(self._get_server_url() + '/iap/account_edi/1/renew_token')
|
||||
if 'error' in response:
|
||||
# can happen if the database was duplicated and the refresh_token was refreshed by the other database.
|
||||
# we don't want two database to be able to query the proxy with the same user
|
||||
|
||||
@@ -470,7 +470,7 @@ class AccountEdiFormat(models.Model):
|
||||
if not invoice_line_form.product_id:
|
||||
for element_code in elements_code:
|
||||
code = element_code.xpath('.//CodiceValore')[0]
|
||||
product = self.env['product.product'].search([('default_code', '=', code.text)])
|
||||
product = self.env['product.product'].search([('default_code', '=', code.text)], limit=1)
|
||||
if product:
|
||||
invoice_line_form.product_id = product
|
||||
break
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from flectra import models, _, _lt
|
||||
from flectra.exceptions import UserError
|
||||
from flectra.addons.account_edi_proxy_client.models.account_edi_proxy_user import AccountEdiProxyError, DEFAULT_SERVER_URL
|
||||
from flectra.addons.account_edi_proxy_client.models.account_edi_proxy_user import AccountEdiProxyError, DEFAULT_SERVER_URL, DEFAULT_TEST_SERVER_URL
|
||||
|
||||
from lxml import etree
|
||||
import base64
|
||||
@@ -22,15 +22,15 @@ class AccountEdiFormat(models.Model):
|
||||
def _cron_receive_fattura_pa(self):
|
||||
''' Check the proxy for incoming invoices.
|
||||
'''
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
proxy_users = self.env['account_edi_proxy_client.user'].search([('edi_format_id', '=', self.env.ref('l10n_it_edi.edi_fatturaPA').id)])
|
||||
|
||||
if proxy_users._get_demo_state() == 'demo':
|
||||
return
|
||||
|
||||
server_url = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
proxy_users = self.env['account_edi_proxy_client.user'].search([('edi_format_id', '=', self.env.ref('l10n_it_edi.edi_fatturaPA').id)])
|
||||
for proxy_user in proxy_users:
|
||||
company = proxy_user.company_id
|
||||
try:
|
||||
res = proxy_user._make_request(server_url + '/api/l10n_it_edi/1/in/RicezioneInvoice',
|
||||
res = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/in/RicezioneInvoice',
|
||||
params={'recipient_codice_fiscale': company.l10n_it_codice_fiscale})
|
||||
except AccountEdiProxyError as e:
|
||||
_logger.error('Error while receiving file from SdiCoop: %s', e)
|
||||
@@ -65,7 +65,7 @@ class AccountEdiFormat(models.Model):
|
||||
|
||||
if proxy_acks:
|
||||
try:
|
||||
proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack',
|
||||
proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/ack',
|
||||
params={'transaction_ids': proxy_acks})
|
||||
except AccountEdiProxyError as e:
|
||||
_logger.error('Error while receiving file from SdiCoop: %s', e)
|
||||
@@ -153,7 +153,7 @@ class AccountEdiFormat(models.Model):
|
||||
'error': _("You must accept the terms and conditions in the settings to use FatturaPA."),
|
||||
'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
if proxy_user._get_demo_state() == 'demo':
|
||||
responses = {filename: {'id_transaction': 'demo'} for invoice in invoices}
|
||||
else:
|
||||
try:
|
||||
@@ -175,7 +175,6 @@ class AccountEdiFormat(models.Model):
|
||||
def _l10n_it_post_invoices_step_2(self, invoices):
|
||||
''' Check if the sent invoices have been processed by FatturaPA.
|
||||
'''
|
||||
server_url = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
to_check = {i.l10n_it_edi_transaction: i for i in invoices}
|
||||
to_return = {}
|
||||
company = invoices.company_id
|
||||
@@ -185,12 +184,12 @@ class AccountEdiFormat(models.Model):
|
||||
'error': _("You must accept the terms and conditions in the settings to use FatturaPA."),
|
||||
'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
if proxy_user._get_demo_state() == 'demo':
|
||||
# simulate success and bypass ack
|
||||
return {invoice: {'attachment': invoice.l10n_it_edi_attachment_id} for invoice in invoices}
|
||||
else:
|
||||
try:
|
||||
responses = proxy_user._make_request(server_url + '/api/l10n_it_edi/1/in/TrasmissioneFatture',
|
||||
responses = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/in/TrasmissioneFatture',
|
||||
params={'ids_transaction': list(to_check.keys())})
|
||||
except AccountEdiProxyError as e:
|
||||
return {invoice: {'error': e.message, 'blocking_level': 'error'} for invoice in invoices}
|
||||
@@ -230,6 +229,7 @@ class AccountEdiFormat(models.Model):
|
||||
elif state == 'notificaScarto':
|
||||
errors = [element.find('Descrizione').text for element in response_tree.xpath('//Errore')]
|
||||
to_return[invoice] = {'error': self._format_error_message(_('The invoice has been refused by the Exchange System'), errors), 'blocking_level': 'error'}
|
||||
invoice.l10n_it_edi_transaction = False
|
||||
elif state == 'notificaMancataConsegna':
|
||||
to_return[invoice] = {
|
||||
'error': _('The E-invoice is not delivered to the addressee. The Exchange System is\
|
||||
@@ -250,7 +250,7 @@ class AccountEdiFormat(models.Model):
|
||||
|
||||
if proxy_acks:
|
||||
try:
|
||||
proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack',
|
||||
proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/ack',
|
||||
params={'transaction_ids': proxy_acks})
|
||||
except AccountEdiProxyError as e:
|
||||
# Will be ignored and acked again next time.
|
||||
@@ -294,8 +294,7 @@ class AccountEdiFormat(models.Model):
|
||||
'EI03': {'error': _lt('Unauthorized user'), 'blocking_level': 'error'},
|
||||
}
|
||||
|
||||
server_url = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.edi_server_url', DEFAULT_SERVER_URL)
|
||||
result = proxy_user._make_request(server_url + '/api/l10n_it_edi/1/out/SdiRiceviFile', params={'files': files})
|
||||
result = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/out/SdiRiceviFile', params={'files': files})
|
||||
|
||||
# Translate the errors.
|
||||
for filename in result.keys():
|
||||
|
||||
@@ -182,7 +182,10 @@ class SaleOrder(models.Model):
|
||||
|
||||
user_id = fields.Many2one(
|
||||
'res.users', string='Salesperson', index=True, tracking=2, default=lambda self: self.env.user,
|
||||
domain=lambda self: [('groups_id', 'in', self.env.ref('sales_team.group_sale_salesman').id)])
|
||||
domain=lambda self: "[('groups_id', '=', {}), ('share', '=', False), ('company_ids', '=', company_id)]".format(
|
||||
self.env.ref("sales_team.group_sale_salesman").id
|
||||
),)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
'res.partner', string='Customer', readonly=True,
|
||||
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
|
||||
|
||||
@@ -661,7 +661,7 @@
|
||||
<page string="Other Info" name="other_information">
|
||||
<group>
|
||||
<group name="sales_person" string="Sales">
|
||||
<field name="user_id" domain="[('share', '=', False)]" widget="many2one_avatar_user"/>
|
||||
<field name="user_id" widget="many2one_avatar_user"/>
|
||||
<field name="team_id" kanban_view_ref="%(sales_team.crm_team_view_kanban)s" options="{'no_create': True}"/>
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="require_signature"/>
|
||||
|
||||
@@ -104,11 +104,10 @@ for move_line in move_lines:
|
||||
move_lines_to_unreserve.append(move_line.id)
|
||||
move_line_to_recompute_ids.append(move_line.id)
|
||||
|
||||
if len(move_lines_to_unreserve) > 0:
|
||||
env.cr.execute("""
|
||||
UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id in %s ;
|
||||
"""
|
||||
% (tuple(move_lines_to_unreserve), ))
|
||||
if len(move_lines_to_unreserve) > 1:
|
||||
env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id in %s ;""" % (tuple(move_lines_to_unreserve), ))
|
||||
elif len(move_lines_to_unreserve) == 1:
|
||||
env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id = %s ;""" % (move_lines_to_unreserve[0]))
|
||||
|
||||
if logging:
|
||||
env['ir.logging'].sudo().create({
|
||||
|
||||
Reference in New Issue
Block a user