mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-08-19 01:34:43 -05:00
[PATCH] Upstream patch - 01032022
This commit is contained in:
@@ -17,7 +17,7 @@ class FlectraEdiProxyAuth(requests.auth.AuthBase):
|
||||
|
||||
def __init__(self, user=False):
|
||||
self.id_client = user and user.id_client or False
|
||||
self.refresh_token = user and user.refresh_token or False
|
||||
self.refresh_token = user and user.sudo().refresh_token or False
|
||||
|
||||
def __call__(self, request):
|
||||
# We don't sign request that still don't have a id_client/refresh_token
|
||||
|
||||
@@ -57,11 +57,11 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
]
|
||||
|
||||
def _get_demo_state(self):
|
||||
demo_state = self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False)
|
||||
demo_state = self.env['ir.config_parameter'].sudo().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)
|
||||
return DEFAULT_TEST_SERVER_URL if self._get_demo_state() == 'test' else self.env['ir.config_parameter'].sudo().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).
|
||||
@@ -104,7 +104,7 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
return self._make_request(url, params)
|
||||
if error_code == 'no_such_user':
|
||||
# This error is also raised if the user didn't exchange data and someone else claimed the edi_identificaiton.
|
||||
self.active = False
|
||||
self.sudo().active = False
|
||||
raise AccountEdiProxyError(error_code, proxy_error['message'] or False)
|
||||
|
||||
return response['result']
|
||||
@@ -182,7 +182,7 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
# we don't want two database to be able to query the proxy with the same user
|
||||
# because it could lead to not inconsistent data.
|
||||
_logger.error(response['error'])
|
||||
self.refresh_token = response['refresh_token']
|
||||
self.sudo().refresh_token = response['refresh_token']
|
||||
|
||||
def _decrypt_data(self, data, symmetric_key):
|
||||
''' Decrypt the data. Note that the data is encrypted with a symmetric key, which is encrypted with an asymmetric key.
|
||||
@@ -192,7 +192,7 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
:param symmetric_key: The symmetric_key encrypted with self.private_key.public_key()
|
||||
'''
|
||||
private_key = serialization.load_pem_private_key(
|
||||
base64.b64decode(self.private_key),
|
||||
base64.b64decode(self.sudo().private_key),
|
||||
password=None,
|
||||
backend=default_backend()
|
||||
)
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_account_edi_proxy_user","access_account_edi_proxy_user","model_account_edi_proxy_client_user","base.group_system",1,1,1,0
|
||||
"access_account_edi_proxy_manager","access_account_edi_proxy_user","model_account_edi_proxy_client_user","base.group_system",1,1,1,1
|
||||
"access_account_edi_proxy_user","access_account_edi_proxy_user","model_account_edi_proxy_client_user","account.group_account_invoice",1,0,0,0
|
||||
|
||||
|
@@ -40,7 +40,8 @@ class SaleOrder(models.Model):
|
||||
|
||||
def _compute_attendee_count(self):
|
||||
sale_orders_data = self.env['event.registration'].read_group(
|
||||
[('sale_order_id', 'in', self.ids)],
|
||||
[('sale_order_id', 'in', self.ids),
|
||||
('state', '!=', 'cancel')],
|
||||
['sale_order_id'], ['sale_order_id']
|
||||
)
|
||||
attendee_count_data = {
|
||||
|
||||
@@ -735,7 +735,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Sales Order">
|
||||
<field name="name" string="Order" filter_domain="['|', '|', ('name', 'ilike', self), ('client_order_ref', 'ilike', self), ('partner_id', 'child_of', self)]"/>
|
||||
<field name="partner_id" operator="child_of" context="{'active_test': False}"/>
|
||||
<field name="partner_id" operator="child_of"/>
|
||||
<field name="user_id"/>
|
||||
<field name="team_id" string="Sales Team"/>
|
||||
<field name="order_line" string="Product" filter_domain="[('order_line.product_id', 'ilike', self)]"/>
|
||||
|
||||
@@ -537,15 +537,17 @@ The correction could unreserve some operations with problematics products.""", p
|
||||
SELECT min(id) as to_update_quant_id,
|
||||
(array_agg(id ORDER BY id))[2:array_length(array_agg(id), 1)] as to_delete_quant_ids,
|
||||
SUM(reserved_quantity) as reserved_quantity,
|
||||
SUM(quantity) as quantity
|
||||
SUM(quantity) as quantity,
|
||||
MIN(in_date) as in_date
|
||||
FROM stock_quant
|
||||
GROUP BY product_id, company_id, location_id, lot_id, package_id, owner_id, in_date
|
||||
GROUP BY product_id, company_id, location_id, lot_id, package_id, owner_id
|
||||
HAVING count(id) > 1
|
||||
),
|
||||
_up AS (
|
||||
UPDATE stock_quant q
|
||||
SET quantity = d.quantity,
|
||||
reserved_quantity = d.reserved_quantity
|
||||
reserved_quantity = d.reserved_quantity,
|
||||
in_date = d.in_date
|
||||
FROM dupes d
|
||||
WHERE d.to_update_quant_id = q.id
|
||||
)
|
||||
|
||||
@@ -701,3 +701,49 @@ class StockQuant(SavepointCase):
|
||||
inventory._action_done()
|
||||
quant = self.env['stock.quant'].search([('product_id', '=', self.product.id), ('location_id', '=', self.stock_location.id), ('quantity', '>', 0)])
|
||||
self.assertEqual(quant.in_date, tomorrow)
|
||||
|
||||
def test_unpack_and_quants_merging(self):
|
||||
"""
|
||||
When unpacking a package, if there are already some quantities of the
|
||||
packed product in the stock, the quant of the on hand quantity and the
|
||||
one of the package should be merged
|
||||
"""
|
||||
stock_location = self.env['stock.warehouse'].search([], limit=1).lot_stock_id
|
||||
supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
picking_type_in = self.env.ref('stock.picking_type_in')
|
||||
|
||||
self.env['stock.quant']._update_available_quantity(self.product, stock_location, 1.0)
|
||||
|
||||
picking = self.env['stock.picking'].create({
|
||||
'picking_type_id': picking_type_in.id,
|
||||
'location_id': supplier_location.id,
|
||||
'location_dest_id': stock_location.id,
|
||||
'move_lines': [(0, 0, {
|
||||
'name': 'In 10 x %s' % self.product.name,
|
||||
'product_id': self.product.id,
|
||||
'location_id': supplier_location.id,
|
||||
'location_dest_id': stock_location.id,
|
||||
'product_uom_qty': 10,
|
||||
'product_uom': self.product.uom_id.id,
|
||||
})],
|
||||
})
|
||||
picking.action_confirm()
|
||||
|
||||
package = self.env['stock.quant.package'].create({
|
||||
'name': 'Super Package',
|
||||
})
|
||||
picking.move_lines.move_line_ids.write({
|
||||
'qty_done': 10,
|
||||
'result_package_id': package.id,
|
||||
})
|
||||
picking.button_validate()
|
||||
|
||||
package.unpack()
|
||||
|
||||
quant = self.env['stock.quant'].search([('product_id', '=', self.product.id), ('on_hand', '=', True)])
|
||||
self.assertEqual(len(quant), 1)
|
||||
# The quants merging is processed thanks to a SQL query (see StockQuant._merge_quants).
|
||||
# At that point, the ORM is not aware of the new value. So we need to invalidate the
|
||||
# cache to ensure that the value will be the newest
|
||||
quant.invalidate_cache(fnames=['quantity'], ids=quant.ids)
|
||||
self.assertEqual(quant.quantity, 11)
|
||||
|
||||
Reference in New Issue
Block a user