From 98072f1ad069943e432385bf26926bc951297a7e Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 24 Nov 2017 11:53:54 +0100 Subject: [PATCH 1/6] [IMP] stock: performance on _compute_reserved_availability Improve performance (* 2.5) on _compute_reserved_availability `mapped` makes use of orm prefetch, which is inefficient in this use case when facing high volume. Closes #21198 --- addons/stock/models/stock_move.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index a5b97bc7938..b9c52991a84 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -179,10 +179,13 @@ class StockMove(models.Model): else: self.lot_ids = self.mapped('reserved_quant_ids').mapped('lot_id').ids - @api.one + @api.multi @api.depends('reserved_quant_ids.qty') def _compute_reserved_availability(self): - self.reserved_availability = sum(self.mapped('reserved_quant_ids').mapped('qty')) + result = {data['reservation_id'][0]: data['qty'] for data in + self.env['stock.quant'].read_group([('reservation_id', 'in', self.ids)], ['reservation_id','qty'], ['reservation_id'])} + for rec in self: + rec.reserved_availability = result.get(rec.id, 0.0) @api.one @api.depends('state', 'product_id', 'product_qty', 'location_id') @@ -651,7 +654,7 @@ class StockMove(models.Model): if move.state != 'assigned' and not self.env.context.get('reserve_only_ops'): qty_already_assigned = move.reserved_availability qty = move.product_qty - qty_already_assigned - + quants = Quant.quants_get_preferred_domain(qty, move, domain=main_domain[move.id], preferred_domain_list=[]) Quant.quants_reserve(quants, move) From ffbcf69af5a06b6d99d4208a17ffa4a368233845 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 12 Dec 2017 11:36:58 +0100 Subject: [PATCH 2/6] [FIX] product_extended: remove not working price computation costs_hour field no longer exists Some modules in a different repository (let say enterprise), may be still using it but it is not its place here. For stability reasons, we keep the computation if an external module adds the missing field anyway Fixes #16269 Closes #20899 --- addons/product_extended/models/product.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/product_extended/models/product.py b/addons/product_extended/models/product.py index f0f886b66d4..0efd659dd79 100644 --- a/addons/product_extended/models/product.py +++ b/addons/product_extended/models/product.py @@ -41,10 +41,12 @@ class ProductProduct(models.Model): # No attribute_value_ids means the bom line is not variant specific price += sbom.product_id.uom_id._compute_price(sbom.product_id.standard_price, sbom.product_uom_id) * sbom_data['qty'] if bom.routing_id: - total_cost = 0.0 - for order in bom.routing_id.operation_ids: - total_cost += (order.time_cycle/60) * order.workcenter_id.costs_hour - price += bom.product_uom_id._compute_price(total_cost, bom.product_id.uom_id) + # FIXME master: remove me + if hasattr(self.env['mrp.workcenter'], 'costs_hour'): + total_cost = 0.0 + for order in bom.routing_id.operation_ids: + total_cost += (order.time_cycle/60) * order.workcenter_id.costs_hour + price += bom.product_uom_id._compute_price(total_cost, bom.product_id.uom_id) # Convert on product UoM quantities if price > 0: price = bom.product_uom_id._compute_price(price / bom.product_qty, self.uom_id) From d82b360309b7a3c5726bbffb2ac008aeffeb2197 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 5 Apr 2017 07:50:53 +0200 Subject: [PATCH 3/6] [CLA] backport signature for Tecnativa backport of dc8010c9b to 9.0 Asked in #21496 --- doc/cla/corporate/tecnativa.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 doc/cla/corporate/tecnativa.md diff --git a/doc/cla/corporate/tecnativa.md b/doc/cla/corporate/tecnativa.md new file mode 100644 index 00000000000..72a73cbbe28 --- /dev/null +++ b/doc/cla/corporate/tecnativa.md @@ -0,0 +1,22 @@ +Spain, 2017-04-04 + +Tecnativa S.L. agrees to the terms of the Odoo Corporate Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Pedro M. Baeza pedro.baeza@tecnativa.com https://github.com/pedrobaeza + +List of contributors: + +Pedro M. Baeza pedro.baeza@tecnativa.com https://github.com/pedrobaeza +Rafael Blasco rafael.blasco@tecnativa.com https://github.com/rafaelbn +Sergio Teruel sergio.teruel@tecnativa.com https://github.com/sergio-teruel +Carlos Dauden carlos.dauden@tecnativa.com https://github.com/carlosdauden +Jairo Llopis jairo.llopis@tecnativa.com https://github.com/yajo +Vicent Cubells vicent.cubells@tecnativa.com https://github.com/cubells +Luis Montalba luis.montalba@tecnativa.com https://github.com/luismontalba +David Vidal david.vidal@tecnativa.com https://github.com/chienandalu From 2720eb84eeeb9fe4b41ef81bd505c4f2857c416d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Mon, 11 Dec 2017 17:17:08 +0100 Subject: [PATCH 4/6] [FIX] website_portal: Verification of vat number in EU country We have problems when trying to validate our EU VAT report because some vat number are wrongly encoded in Odoo. There are 2 problems: 1) We use vatnumber library to check the validity of the VAT number entered by the user on website. That library removes the following characters '.' and '-' in order to perform the check and thus can return True for a number like 123.123.123.13 or -123-3454-34 And those VAT number are then saved in our database but are rejected by the state as VAT number should only contains alphanumeric character -> Solution: prevent entering vat number with other characters than alphanumeric for users that are located in EUROPE! 2) Usually VAT is prefixed by country code, however some people in europe managed to bypass the system by prefixing their VAT number with CC instead of their country code, CC is consider valid in odoo (it means Country Code) but is not a valid European country code in general, which means that those people that should have pay some tax have not. Which is a huge problem. -> Solution: prevent the use of CC as country code by the user when entering a vatnumber only if the user country is in EUROPE! source: https://en.wikipedia.org/wiki/VAT_identification_number opw:785443 --- addons/website_portal/controllers/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/website_portal/controllers/main.py b/addons/website_portal/controllers/main.py index 117e0f7dba7..e5bf6b12ef1 100644 --- a/addons/website_portal/controllers/main.py +++ b/addons/website_portal/controllers/main.py @@ -105,6 +105,8 @@ class website_account(http.Controller): # vat validation if data.get("vat") and hasattr(request.env["res.partner"], "check_vat"): + if data.get("country_id"): + data["vat"] = request.env["res.partner"].fix_eu_vat_number(int(data.get("country_id")), data.get("vat")) if request.website.company_id.sudo().vat_check_vies: # force full VIES online check check_func = request.env["res.partner"].vies_vat_check From eb36f427292e7f0777d3da0093be51b9f56ca14c Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Tue, 12 Dec 2017 10:16:11 +0100 Subject: [PATCH 5/6] [FIX] stock: complete_name of stock location Have the following location structure: Loc A -> Loc B -> Loc C The `complete_name` fields are: - Loc A - Loc A/Loc B - Loc A/Loc B/Loc C When changing Loc A to Loc D, the `complete_name` are: - Loc D - Loc D/Loc B - Loc A/Loc B/Loc C Compute `complete_name` of stock location using `complete_name` of parent instead of parsing the full bunch of ancestors. This improves the computation speed, and moreover solves the recursivity problem. Closes #21585 --- addons/stock/models/stock_location.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index eb88b140a1b..aed705023fd 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -69,15 +69,13 @@ class Location(models.Model): _sql_constraints = [('barcode_company_uniq', 'unique (barcode,company_id)', 'The barcode for a location must be unique per company !')] @api.one - @api.depends('name', 'location_id.name') + @api.depends('name', 'location_id.complete_name') def _compute_complete_name(self): """ Forms complete name of location from parent location to child location. """ - name = self.name - current = self - while current.location_id: - current = current.location_id - name = '%s/%s' % (current.name, name) - self.complete_name = name + if self.location_id.complete_name: + self.complete_name = '%s/%s' % (self.location_id.complete_name, self.name) + else: + self.complete_name = self.name @api.multi def name_get(self): From 7a24a2f45f1d627f2f5978cda7e2fadbe41226e5 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 12 Dec 2017 13:36:23 +0100 Subject: [PATCH 6/6] [FIX] field: avoid overhead of record._set_dirty when setting fields (#21378) Setting fields as dirty was dramatically slow for huge one2many fields. --- openerp/fields.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openerp/fields.py b/openerp/fields.py index 4b2b5e443b5..c96eb7dacaa 100644 --- a/openerp/fields.py +++ b/openerp/fields.py @@ -851,11 +851,11 @@ class Field(object): spec = self.modified_draft(record) # set value in cache, inverse field, and mark record as dirty - record._cache[self] = value + env.cache[self][record.id] = value if env.in_onchange: for invf in record._field_inverses[self]: invf._update(value, record) - record._set_dirty(self.name) + env.dirty[record].add(self.name) # determine more dependent fields, and invalidate them if self.relational: @@ -867,7 +867,7 @@ class Field(object): record.write({self.name: self.convert_to_write(value)}) # Update the cache unless value contains a new record if all(getattr(value, '_ids', ())): - record._cache[self] = value + env.cache[self][record.id] = value ############################################################################ #