From 414c3bc89a95aa2fed9ba045cd29f640638e1b2e Mon Sep 17 00:00:00 2001 From: "jim.hoefnagels" Date: Wed, 5 Feb 2020 11:26:32 +0100 Subject: [PATCH] [MIG] stock_cycle_count: Migration to 13.0 --- .../odoo/addons/stock_cycle_count | 1 + setup/stock_cycle_count/setup.py | 6 + stock_cycle_count/__manifest__.py | 10 +- .../data/cycle_count_ir_cron.xml | 14 +- .../data/cycle_count_sequence.xml | 7 +- stock_cycle_count/i18n/stock_cycle_count.pot | 2 +- stock_cycle_count/models/stock_cycle_count.py | 14 +- .../models/stock_cycle_count_rule.py | 8 +- stock_cycle_count/models/stock_inventory.py | 4 - stock_cycle_count/models/stock_location.py | 13 +- stock_cycle_count/models/stock_move.py | 7 +- stock_cycle_count/models/stock_warehouse.py | 3 - stock_cycle_count/readme/CONTRIBUTORS.rst | 1 + stock_cycle_count/readme/HISTORY.rst | 6 + .../reports/report_stock_location_accuracy.py | 1 - .../reports/stock_cycle_count_report.xml | 25 +- .../stock_location_accuracy_report.xml | 33 +-- .../tests/test_stock_cycle_count.py | 18 +- .../views/stock_cycle_count_rule_view.xml | 97 ++++---- .../views/stock_cycle_count_view.xml | 226 ++++++++++-------- .../views/stock_inventory_view.xml | 56 ++--- .../views/stock_location_view.xml | 29 +-- .../views/stock_warehouse_view.xml | 27 +-- 23 files changed, 309 insertions(+), 299 deletions(-) create mode 120000 setup/stock_cycle_count/odoo/addons/stock_cycle_count create mode 100644 setup/stock_cycle_count/setup.py diff --git a/setup/stock_cycle_count/odoo/addons/stock_cycle_count b/setup/stock_cycle_count/odoo/addons/stock_cycle_count new file mode 120000 index 000000000..5259223f1 --- /dev/null +++ b/setup/stock_cycle_count/odoo/addons/stock_cycle_count @@ -0,0 +1 @@ +../../../../stock_cycle_count \ No newline at end of file diff --git a/setup/stock_cycle_count/setup.py b/setup/stock_cycle_count/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_cycle_count/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_cycle_count/__manifest__.py b/stock_cycle_count/__manifest__.py index f04d6ee4b..a2a6c24cf 100644 --- a/stock_cycle_count/__manifest__.py +++ b/stock_cycle_count/__manifest__.py @@ -1,14 +1,14 @@ -# Copyright 2017-18 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2017-18 ForgeFlow Business and IT Consulting Services S.L. +# (http://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Stock Cycle Count", "summary": "Adds the capability to schedule cycle counts in a " "warehouse through different rules defined by the user.", - "version": "12.0.1.0.1", + "version": "13.0.1.0.0", "development_status": "Mature", - "maintainers": ["lreficent"], - "author": "Eficent, " "Odoo Community Association (OCA)", + "maintainers": ["LoisRForgeFlow"], + "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", "depends": [ diff --git a/stock_cycle_count/data/cycle_count_ir_cron.xml b/stock_cycle_count/data/cycle_count_ir_cron.xml index 77fbf6c90..80506b733 100644 --- a/stock_cycle_count/data/cycle_count_ir_cron.xml +++ b/stock_cycle_count/data/cycle_count_ir_cron.xml @@ -1,20 +1,16 @@ - + - - - + Cycle Count Planner Computation code - + 1 days -1 - - + + model.cron_cycle_count() - diff --git a/stock_cycle_count/data/cycle_count_sequence.xml b/stock_cycle_count/data/cycle_count_sequence.xml index f98782944..deb21f74f 100644 --- a/stock_cycle_count/data/cycle_count_sequence.xml +++ b/stock_cycle_count/data/cycle_count_sequence.xml @@ -1,15 +1,12 @@ - + - - Cycle Count stock.cycle.count CC/%(range_year)s/ 5 - + - diff --git a/stock_cycle_count/i18n/stock_cycle_count.pot b/stock_cycle_count/i18n/stock_cycle_count.pot index a8da0d6cf..fe3c4e06d 100644 --- a/stock_cycle_count/i18n/stock_cycle_count.pot +++ b/stock_cycle_count/i18n/stock_cycle_count.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py index f03efc249..50de7faf4 100644 --- a/stock_cycle_count/models/stock_cycle_count.py +++ b/stock_cycle_count/models/stock_cycle_count.py @@ -12,11 +12,6 @@ class StockCycleCount(models.Model): _inherit = "mail.thread" _order = "id desc" - @api.model - def _default_company(self): - company_id = self.env["res.company"]._company_default_get(self._name) - return company_id - name = fields.Char(string="Name", readonly=True) location_id = fields.Many2one( comodel_name="stock.location", @@ -68,27 +63,24 @@ class StockCycleCount(models.Model): comodel_name="res.company", string="Company", required=True, - default=_default_company, + default=lambda self: self.env.company, readonly=True, ) @api.depends("stock_adjustment_ids") - @api.multi def _compute_inventory_adj_count(self): for rec in self: rec.inventory_adj_count = len(rec.stock_adjustment_ids) - @api.multi def do_cancel(self): self.write({"state": "cancelled"}) - @api.multi def _prepare_inventory_adjustment(self): self.ensure_one() return { "name": "INV/{}".format(self.name), "cycle_count_id": self.id, - "location_id": self.location_id.id, + "location_ids": [(4, self.location_id.id)], "exclude_sublocation": True, } @@ -97,7 +89,6 @@ class StockCycleCount(models.Model): vals["name"] = self.env["ir.sequence"].next_by_code("stock.cycle.count") or "" return super(StockCycleCount, self).create(vals) - @api.multi def action_create_inventory_adjustment(self): if any([s != "draft" for s in self.mapped("state")]): raise UserError(_("You can only confirm cycle counts in state 'Planned'.")) @@ -107,7 +98,6 @@ class StockCycleCount(models.Model): self.write({"state": "open"}) return True - @api.multi def action_view_inventory(self): action = self.env.ref("stock.action_inventory_form") result = action.read()[0] diff --git a/stock_cycle_count/models/stock_cycle_count_rule.py b/stock_cycle_count/models/stock_cycle_count_rule.py index 2cb71963c..d662e254c 100644 --- a/stock_cycle_count/models/stock_cycle_count_rule.py +++ b/stock_cycle_count/models/stock_cycle_count_rule.py @@ -12,7 +12,6 @@ class StockCycleCountRule(models.Model): _name = "stock.cycle.count.rule" _description = "Stock Cycle Counts Rules" - @api.multi def _compute_currency_id(self): for rec in self: rec.currency_id = self.env.user.company_id.currency_id @@ -26,7 +25,6 @@ class StockCycleCountRule(models.Model): ("zero", _("Zero Confirmation")), ] - @api.multi @api.constrains("rule_type", "warehouse_ids") def _check_zero_rule(self): for rec in self: @@ -83,7 +81,6 @@ class StockCycleCountRule(models.Model): else: self.rule_description = _("(No description provided.)") - @api.multi @api.constrains("periodic_qty_per_period", "periodic_count_period") def _check_negative_periodic(self): for rec in self: @@ -174,7 +171,7 @@ class StockCycleCountRule(models.Model): self.env["stock.inventory"] .search( [ - ("location_id", "=", loc.id), + ("location_ids", "in", [loc.id]), ("state", "in", ["confirm", "done", "draft"]), ], order="date desc", @@ -231,7 +228,7 @@ class StockCycleCountRule(models.Model): self.env["stock.inventory"] .search( [ - ("location_id", "=", loc.id), + ("location_ids", "in", [loc.id]), ("state", "in", ["confirm", "done", "draft"]), ] ) @@ -264,7 +261,6 @@ class StockCycleCountRule(models.Model): cycle_counts.append(cycle_count) return cycle_counts - @api.multi def _compute_rule_accuracy(self, locs): self.ensure_one() cycle_counts = [] diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py index aeb3e7a98..017079b9d 100644 --- a/stock_cycle_count/models/stock_inventory.py +++ b/stock_cycle_count/models/stock_inventory.py @@ -11,7 +11,6 @@ PERCENT = 100.0 class StockInventory(models.Model): _inherit = "stock.inventory" - @api.multi @api.depends("state", "line_ids") def _compute_inventory_accuracy(self): for inv in self: @@ -44,19 +43,16 @@ class StockInventory(models.Model): inv.cycle_count_id.state = "done" return True - @api.multi def action_validate(self): res = super(StockInventory, self).action_validate() self._update_cycle_state() return res - @api.multi def action_force_done(self): res = super(StockInventory, self).action_force_done() self._update_cycle_state() return res - @api.multi def write(self, vals): for inventory in self: if ( diff --git a/stock_cycle_count/models/stock_location.py b/stock_cycle_count/models/stock_location.py index 979f7211b..1ddfba310 100644 --- a/stock_cycle_count/models/stock_location.py +++ b/stock_cycle_count/models/stock_location.py @@ -5,7 +5,7 @@ import logging from datetime import datetime -from odoo import api, fields, models, tools +from odoo import fields, models, tools from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT _logger = logging.getLogger(__name__) @@ -21,13 +21,12 @@ except (ImportError, IOError) as err: class StockLocation(models.Model): _inherit = "stock.location" - @api.multi def _compute_loc_accuracy(self): for rec in self: history = self.env["stock.inventory"].search( - [("location_id", "=", rec.id), ("state", "=", "done")] + [("location_ids", "in", rec.id), ("state", "=", "done")], + order="write_date desc", ) - history = history.sorted(key=lambda r: r.write_date, reverse=True) if history: wh = rec.get_warehouse() if ( @@ -41,6 +40,8 @@ class StockLocation(models.Model): ) else: rec.loc_accuracy = mean(history.mapped("inventory_accuracy")) + else: + rec.loc_accuracy = 0 zero_confirmation_disabled = fields.Boolean( string="Disable Zero Confirmations", @@ -59,13 +60,11 @@ class StockLocation(models.Model): string="Inventory Accuracy", compute="_compute_loc_accuracy", digits=(3, 2) ) - @api.multi def _get_zero_confirmation_domain(self): self.ensure_one() domain = [("location_id", "=", self.id), ("quantity", ">", 0.0)] return domain - @api.multi def check_zero_confirmation(self): for rec in self: if not rec.zero_confirmation_disabled: @@ -81,7 +80,6 @@ class StockLocation(models.Model): if not quants: rec.create_zero_confirmation_cycle_count() - @api.multi def create_zero_confirmation_cycle_count(self): self.ensure_one() date = datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT) @@ -113,7 +111,6 @@ class StockLocation(models.Model): ) return True - @api.multi def action_accuracy_stats(self): self.ensure_one() action = self.env.ref("stock_cycle_count.act_accuracy_stats") diff --git a/stock_cycle_count/models/stock_move.py b/stock_cycle_count/models/stock_move.py index 05caeae95..e088b9360 100644 --- a/stock_cycle_count/models/stock_move.py +++ b/stock_cycle_count/models/stock_move.py @@ -3,14 +3,13 @@ # Copyright 2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, models +from odoo import models class StockMove(models.Model): _inherit = "stock.move" - @api.multi - def _action_done(self): - res = super()._action_done() + def _action_done(self, cancel_backorder=False): + res = super()._action_done(cancel_backorder=cancel_backorder) self.mapped("location_id").check_zero_confirmation() return res diff --git a/stock_cycle_count/models/stock_warehouse.py b/stock_cycle_count/models/stock_warehouse.py index 485943761..ca2b77d74 100644 --- a/stock_cycle_count/models/stock_warehouse.py +++ b/stock_cycle_count/models/stock_warehouse.py @@ -31,7 +31,6 @@ class StockWarehouse(models.Model): help="Number of latest inventories used to calculate location " "accuracy", ) - @api.multi def get_horizon_date(self): self.ensure_one() date = datetime.today() @@ -61,7 +60,6 @@ class StockWarehouse(models.Model): ) return locations - @api.multi def _cycle_count_rules_to_compute(self): self.ensure_one() rules = self.env["stock.cycle.count.rule"].search( @@ -78,7 +76,6 @@ class StockWarehouse(models.Model): "state": "draft", } - @api.multi def action_compute_cycle_count_rules(self): """ Apply the rule in all the sublocations of a given warehouse(s) and returns a list with required dates for the cycle count of each diff --git a/stock_cycle_count/readme/CONTRIBUTORS.rst b/stock_cycle_count/readme/CONTRIBUTORS.rst index 18282827f..a0d627fee 100644 --- a/stock_cycle_count/readme/CONTRIBUTORS.rst +++ b/stock_cycle_count/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Lois Rilo * Jordi Ballester Alomar * Bhavesh Odedra +* Jim Hoefnagels diff --git a/stock_cycle_count/readme/HISTORY.rst b/stock_cycle_count/readme/HISTORY.rst index 7ea18b3f3..ff321c386 100644 --- a/stock_cycle_count/readme/HISTORY.rst +++ b/stock_cycle_count/readme/HISTORY.rst @@ -1,3 +1,9 @@ +13.0.1.0.0 (2020-02-05) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [MIG] Migrated to v13. + + 12.0.1.0.0 (2019-06-24) ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/stock_cycle_count/reports/report_stock_location_accuracy.py b/stock_cycle_count/reports/report_stock_location_accuracy.py index d539d20da..cefc0e88b 100644 --- a/stock_cycle_count/reports/report_stock_location_accuracy.py +++ b/stock_cycle_count/reports/report_stock_location_accuracy.py @@ -26,7 +26,6 @@ class LocationAccuracyReport(models.AbstractModel): data[loc] = counts return data - @api.multi def render_html(self, data=None): report_obj = self.env["report"] locs = self.env["stock.location"].browse(self._ids) diff --git a/stock_cycle_count/reports/stock_cycle_count_report.xml b/stock_cycle_count/reports/stock_cycle_count_report.xml index 54bfb5eb9..6b4d8a24c 100644 --- a/stock_cycle_count/reports/stock_cycle_count_report.xml +++ b/stock_cycle_count/reports/stock_cycle_count_report.xml @@ -1,14 +1,11 @@ - + - - - - + groups="stock.group_stock_user" + /> diff --git a/stock_cycle_count/reports/stock_location_accuracy_report.xml b/stock_cycle_count/reports/stock_location_accuracy_report.xml index 84ed22cc2..e429c2660 100644 --- a/stock_cycle_count/reports/stock_location_accuracy_report.xml +++ b/stock_cycle_count/reports/stock_location_accuracy_report.xml @@ -1,66 +1,57 @@ - + - - - - + groups="stock.group_stock_user" + /> diff --git a/stock_cycle_count/tests/test_stock_cycle_count.py b/stock_cycle_count/tests/test_stock_cycle_count.py index 80bfef2d4..adc8f4b35 100644 --- a/stock_cycle_count/tests/test_stock_cycle_count.py +++ b/stock_cycle_count/tests/test_stock_cycle_count.py @@ -70,7 +70,7 @@ class TestStockCycleCount(common.TransactionCase): self.stock_location_model._parent_store_compute() # Create a cycle count: - self.cycle_count_1 = self.cycle_count_model.sudo(self.manager).create( + self.cycle_count_1 = self.cycle_count_model.with_user(self.manager).create( { "name": "Test cycle count", "cycle_count_rule_id": self.rule_periodic.id, @@ -98,7 +98,7 @@ class TestStockCycleCount(common.TransactionCase): return user def _create_stock_cycle_count_rule_periodic(self, uid, name, values): - rule = self.stock_cycle_count_rule_model.sudo(uid).create( + rule = self.stock_cycle_count_rule_model.with_user(uid).create( { "name": name, "rule_type": "periodic", @@ -109,7 +109,7 @@ class TestStockCycleCount(common.TransactionCase): return rule def _create_stock_cycle_count_rule_turnover(self, uid, name, values): - rule = self.stock_cycle_count_rule_model.sudo(uid).create( + rule = self.stock_cycle_count_rule_model.with_user(uid).create( { "name": name, "rule_type": "turnover", @@ -119,7 +119,7 @@ class TestStockCycleCount(common.TransactionCase): return rule def _create_stock_cycle_count_rule_accuracy(self, uid, name, values, zone_ids): - rule = self.stock_cycle_count_rule_model.sudo(uid).create( + rule = self.stock_cycle_count_rule_model.with_user(uid).create( { "name": name, "rule_type": "accuracy", @@ -131,7 +131,7 @@ class TestStockCycleCount(common.TransactionCase): return rule def _create_stock_cycle_count_rule_zero(self, uid, name): - rule = self.stock_cycle_count_rule_model.sudo(uid).create( + rule = self.stock_cycle_count_rule_model.with_user(uid).create( {"name": name, "rule_type": "zero"} ) return rule @@ -161,7 +161,11 @@ class TestStockCycleCount(common.TransactionCase): ) date = datetime.today() - timedelta(days=1) self.inventory_model.create( - {"name": "Pre-existing inventory", "location_id": loc.id, "date": date} + { + "name": "Pre-existing inventory", + "location_ids": [(4, loc.id)], + "date": date, + } ) self.quant_model.create( { @@ -266,7 +270,7 @@ class TestStockCycleCount(common.TransactionCase): with self.assertRaises(AccessError): self._create_stock_cycle_count_rule_periodic(self.user, "rule_1b", [2, 7]) with self.assertRaises(AccessError): - self.cycle_count_1.sudo(self.user).unlink() + self.cycle_count_1.with_user(self.user).unlink() def test_rule_periodic_constrains(self): """Tests the constrains for the periodic rules.""" diff --git a/stock_cycle_count/views/stock_cycle_count_rule_view.xml b/stock_cycle_count/views/stock_cycle_count_rule_view.xml index 0eb7972a7..cabff2d39 100644 --- a/stock_cycle_count/views/stock_cycle_count_rule_view.xml +++ b/stock_cycle_count/views/stock_cycle_count_rule_view.xml @@ -1,7 +1,6 @@ - + - @@ -9,10 +8,10 @@ stock.cycle.count.rule - - - - + + + + @@ -22,29 +21,38 @@ stock.cycle.count.rule
- - - - - + + + + - - - - -