[PATCH] Upstream patch - 22102023

This commit is contained in:
Parthiv Patel
2023-10-22 08:34:26 +00:00
parent af4f42781d
commit c2f8e93420
10 changed files with 53 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from flectra import api, fields, models, _
from flectra.addons.base.models.decimal_precision import DecimalPrecision
from flectra.exceptions import RedirectWarning, UserError, ValidationError, AccessError
from flectra.tools import float_compare, date_utils, email_split, email_re, float_is_zero
from flectra.tools.misc import formatLang, format_date, get_lang
@@ -8,9 +9,11 @@ from flectra.osv import expression
from datetime import date, timedelta
from collections import defaultdict
from contextlib import contextmanager
from itertools import zip_longest
from hashlib import sha256
from json import dumps
from unittest.mock import patch
import ast
import json
@@ -3192,6 +3195,21 @@ class AccountMove(models.Model):
return rslt
@contextmanager
def _disable_discount_precision(self):
"""Disable the user defined precision for discounts.
This is useful for importing documents coming from other softwares and providers.
The reasonning is that if the document that we are importing has a discount, it
shouldn't be rounded to the local settings.
"""
original_precision_get = DecimalPrecision.precision_get
def precision_get(self, application):
if application == 'Discount':
return 100
return original_precision_get(self, application)
with patch('flectra.addons.base.models.decimal_precision.DecimalPrecision.precision_get', new=precision_get):
yield
def _message_post_after_hook(self, new_message, message_values):
# OVERRIDE
# When posting a message, check the attachment to see if it's an invoice and update with the imported data.
@@ -3220,9 +3238,10 @@ class AccountMove(models.Model):
# start with message_main_attachment_id, that way if OCR is installed, only that one will be parsed.
# this is based on the fact that the ocr will be the last decoder.
for attachment in attachments.sorted(lambda x: x != self.message_main_attachment_id):
invoice = decoder[1](attachment, self)
if invoice:
return res
with self._disable_discount_precision():
invoice = decoder[1](attachment, self)
if invoice:
return res
return res

View File

@@ -18,7 +18,7 @@ TYPE_TAX_USE = [
class AccountTaxGroup(models.Model):
_name = 'account.tax.group'
_description = 'Tax Group'
_order = 'sequence asc'
_order = 'sequence asc, id'
name = fields.Char(required=True, translate=True)
sequence = fields.Integer(default=10)

View File

@@ -595,7 +595,7 @@ class AccountEdiCommon(models.AbstractModel):
elif net_price_unit is not None:
price_unit = (net_price_unit + rebate) / basis_qty
elif price_subtotal is not None:
price_unit = (price_subtotal + allow_charge_amount) / billed_qty
price_unit = (price_subtotal + allow_charge_amount) / (billed_qty or 1)
else:
raise UserError(_("No gross price, net price nor line subtotal amount found for line in xml"))

View File

@@ -45,7 +45,7 @@ _ref_vat = {
'fr': 'FR23334175221',
'gb': 'GB123456782 or XI123456782',
'gr': 'GR12345670',
'hu': 'HU12345676',
'hu': 'HU12345676 or 12345678-1-11 or 8071592153',
'hr': 'HR01234567896', # Croatia, contributed by Milan Tribuson
'ie': 'IE1234567FA',
'in': "12AAAAA1234AAZA",
@@ -232,6 +232,25 @@ class ResPartner(models.Model):
return True
return False
__check_tin_hu_individual_re = re.compile(r'^8\d{9}$')
__check_tin_hu_companies_re = re.compile(r'^\d{8}-[1-5]-\d{2}$')
def check_vat_hu(self, vat):
"""
Check Hungary VAT number that can be for example 'HU12345676 or 'xxxxxxxx-y-zz' or '8xxxxxxxxy'
- For xxxxxxxx-y-zz, 'x' can be any number, 'y' is a number between 1 and 5 depending on the person and the 'zz'
is used for region code.
- 8xxxxxxxxy, Tin number for individual, it has to start with an 8 and finish with the check digit
"""
companies = self.__check_tin_hu_companies_re.match(vat)
if companies:
return True
individual = self.__check_tin_hu_individual_re.match(vat)
if individual:
return True
# Check the vat number
return stdnum.util.get_cc_module('hu', 'vat').is_valid(vat)
__check_vat_ch_re = re.compile(r'E([0-9]{9}|-[0-9]{3}\.[0-9]{3}\.[0-9]{3})(MWST|TVA|IVA)$')
def check_vat_ch(self, vat):

View File

@@ -7,6 +7,8 @@ from flectra.addons.account_edi.tests.common import AccountEdiTestCommon
from flectra import fields
from flectra.modules.module import get_resource_path
from flectra.tests import tagged
from flectra.tools import float_round
from lxml import etree
@@ -135,7 +137,8 @@ class TestUBLCommon(AccountEdiTestCommon):
if list_line_price_unit:
self.assertEqual(invoice.invoice_line_ids.mapped('price_unit'), list_line_price_unit)
if list_line_discount:
self.assertEqual(invoice.invoice_line_ids.mapped('discount'), list_line_discount)
dp = self.env['decimal.precision'].precision_get("Discount")
self.assertListEqual([float_round(line.discount, precision_digits=dp) for line in invoice.invoice_line_ids], list_line_discount)
if list_line_taxes:
for line, taxes in zip(invoice.invoice_line_ids, list_line_taxes):
self.assertEqual(line.tax_ids, taxes)

View File

@@ -81,7 +81,6 @@ class MicrosoftService(models.AbstractModel):
'state': json.dumps(state),
'scope': scope,
'redirect_uri': base_url + '/microsoft_account/authentication',
'prompt': 'consent',
'access_type': 'offline'
})
return "%s?%s" % (MICROSOFT_AUTH_ENDPOINT, encoded_params)

View File

@@ -42,8 +42,8 @@ class WebsiteVisitor(models.Model):
country_flag = fields.Char(related="country_id.image_url", string="Country Flag")
lang_id = fields.Many2one('res.lang', string='Language', help="Language from the website when visitor has been created")
timezone = fields.Selection(_tz_get, string='Timezone')
email = fields.Char(string='Email', compute='_compute_email_phone')
mobile = fields.Char(string='Mobile Phone', compute='_compute_email_phone')
email = fields.Char(string='Email', compute='_compute_email_phone', compute_sudo=True)
mobile = fields.Char(string='Mobile Phone', compute='_compute_email_phone', compute_sudo=True)
# Visit fields
visit_count = fields.Integer('Number of visits', default=1, readonly=True, help="A new visit is considered if last connection was more than 8 hours ago.")

View File

@@ -21,7 +21,7 @@ class WebsiteVisitor(models.Model):
self.flush()
left_visitors = self.filtered(lambda visitor: not visitor.email or not visitor.mobile)
leads = left_visitors.sudo().mapped('lead_ids').sorted('create_date', reverse=True)
leads = left_visitors.mapped('lead_ids').sorted('create_date', reverse=True)
visitor_to_lead_ids = dict((visitor.id, visitor.lead_ids.ids) for visitor in left_visitors)
for visitor in left_visitors:

View File

@@ -32,6 +32,7 @@
<button name="%(website_event.event_registration_action_from_visitor)d"
type="action"
class="oe_stat_button" icon="fa-ticket"
groups="event.group_event_user"
attrs="{'invisible': [('event_registration_count', '=', 0)]}">
<field name="event_registration_count" widget="statinfo" string="Registrations"/>
</button>

View File

@@ -21,6 +21,7 @@
<button name="%(website_event_track.event_track_action_from_visitor)d"
type="action"
class="oe_stat_button" icon="fa-ticket"
groups="event.group_event_manager"
attrs="{'invisible': [('event_track_wishlisted_count', '=', 0)]}">
<field name="event_track_wishlisted_count" widget="statinfo" string="Tracks"/>
</button>