From dcafa2567f5470a9e8db39c6963ec441aad955b7 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 24 Aug 2017 10:47:04 +0200 Subject: [PATCH] [10.0][MIG] stock_cycle_count --- stock_cycle_count/README.rst | 7 ++-- stock_cycle_count/__init__.py | 2 - stock_cycle_count/__manifest__.py | 38 +++++++++++++++++++ stock_cycle_count/__openerp__.py | 36 ------------------ .../data/cycle_count_ir_cron.xml | 32 ++++++++-------- .../data/cycle_count_sequence.xml | 4 +- stock_cycle_count/models/__init__.py | 2 - stock_cycle_count/models/stock_cycle_count.py | 32 ++++++++-------- .../models/stock_cycle_count_rule.py | 14 +++---- stock_cycle_count/models/stock_inventory.py | 8 ++-- stock_cycle_count/models/stock_location.py | 21 +++++----- stock_cycle_count/models/stock_move.py | 2 +- stock_cycle_count/models/stock_warehouse.py | 21 +++++++--- .../reports/report_stock_location_accuracy.py | 2 +- stock_cycle_count/tests/__init__.py | 2 - .../tests/test_stock_cycle_count.py | 6 +-- .../views/stock_cycle_count_rule_view.xml | 6 ++- .../views/stock_cycle_count_view.xml | 2 +- .../views/stock_location_view.xml | 18 +++++---- .../views/stock_warehouse_view.xml | 2 +- 20 files changed, 130 insertions(+), 127 deletions(-) create mode 100644 stock_cycle_count/__manifest__.py delete mode 100644 stock_cycle_count/__openerp__.py diff --git a/stock_cycle_count/README.rst b/stock_cycle_count/README.rst index 743f0114a..f772d0486 100644 --- a/stock_cycle_count/README.rst +++ b/stock_cycle_count/README.rst @@ -37,9 +37,9 @@ Recommendations It is highly recommended to use this module in conjunction with: -* `stock_inventory_verification_request`: Adds the capability to request Slot +* ``stock_inventory_verification_request``: Adds the capability to request Slot Verifications. -* `stock_inventory_lockdown`: Lock down locations during inventories. +* ``stock_inventory_lockdown``: Lock down locations during inventories. Configuration ============= @@ -72,7 +72,7 @@ is described below. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/9.0 + :target: https://runbot.odoo-community.org/runbot/153/10.0 Bug Tracker @@ -95,7 +95,6 @@ Contributors * Lois Rilo * Jordi Ballester Alomar - Maintainer ---------- diff --git a/stock_cycle_count/__init__.py b/stock_cycle_count/__init__.py index f1ca255e7..207b1f3f6 100644 --- a/stock_cycle_count/__init__.py +++ b/stock_cycle_count/__init__.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -# Copyright 2016 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models diff --git a/stock_cycle_count/__manifest__.py b/stock_cycle_count/__manifest__.py new file mode 100644 index 000000000..54a16699c --- /dev/null +++ b/stock_cycle_count/__manifest__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2017-18 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.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": "10.0.1.0.0", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse Management", + "depends": [ + "stock", + "mail", + "stock_inventory_discrepancy", + "stock_inventory_exclude_sublocation", + ], + "external_dependencies": { + "python": ["numpy"], + }, + "data": [ + "views/stock_cycle_count_view.xml", + "views/stock_cycle_count_rule_view.xml", + "views/stock_warehouse_view.xml", + "views/stock_inventory_view.xml", + "views/stock_location_view.xml", + "data/cycle_count_sequence.xml", + "data/cycle_count_ir_cron.xml", + "reports/stock_location_accuracy_report.xml", + "reports/stock_cycle_count_report.xml", + "security/ir.model.access.csv", + ], + "license": "AGPL-3", + "installable": True, + "application": False, +} diff --git a/stock_cycle_count/__openerp__.py b/stock_cycle_count/__openerp__.py deleted file mode 100644 index 8542d87a5..000000000 --- a/stock_cycle_count/__openerp__.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.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": "9.0.1.2.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", - "website": "https://github.com/OCA/stock-logistics-warehouse", - "category": "Warehouse Management", - "depends": ["stock", - "mail", - "stock_inventory_discrepancy", - "stock_inventory_exclude_sublocation"], - "external_dependencies": { - "python": ['numpy'], - }, - "data": [ - 'views/stock_cycle_count_view.xml', - 'views/stock_cycle_count_rule_view.xml', - 'views/stock_warehouse_view.xml', - 'views/stock_inventory_view.xml', - 'views/stock_location_view.xml', - 'data/cycle_count_sequence.xml', - 'data/cycle_count_ir_cron.xml', - 'reports/stock_location_accuracy_report.xml', - 'reports/stock_cycle_count_report.xml', - 'security/ir.model.access.csv', - ], - "license": "AGPL-3", - 'installable': True, - 'application': False, -} diff --git a/stock_cycle_count/data/cycle_count_ir_cron.xml b/stock_cycle_count/data/cycle_count_ir_cron.xml index 0f850b896..c56fbdf76 100644 --- a/stock_cycle_count/data/cycle_count_ir_cron.xml +++ b/stock_cycle_count/data/cycle_count_ir_cron.xml @@ -2,19 +2,19 @@ - - - - Cycle Count Planner Computation - - 1 - days - -1 - - - - - - - + + + + Cycle Count Planner Computation + + 1 + days + -1 + + + + + + + diff --git a/stock_cycle_count/data/cycle_count_sequence.xml b/stock_cycle_count/data/cycle_count_sequence.xml index ca0b5dd0c..00a0445ff 100644 --- a/stock_cycle_count/data/cycle_count_sequence.xml +++ b/stock_cycle_count/data/cycle_count_sequence.xml @@ -2,8 +2,7 @@ - - + Cycle Count @@ -13,5 +12,4 @@ - diff --git a/stock_cycle_count/models/__init__.py b/stock_cycle_count/models/__init__.py index 0ef49bf90..04c24269d 100644 --- a/stock_cycle_count/models/__init__.py +++ b/stock_cycle_count/models/__init__.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import stock_cycle_count diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py index ebd8f86d0..36999b62b 100644 --- a/stock_cycle_count/models/stock_cycle_count.py +++ b/stock_cycle_count/models/stock_cycle_count.py @@ -3,8 +3,8 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models, _ -from openerp.exceptions import UserError +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class StockCycleCount(models.Model): @@ -12,9 +12,10 @@ class StockCycleCount(models.Model): _description = "Stock Cycle Counts" _inherit = 'mail.thread' - @api.one + @api.multi def _count_inventory_adj(self): - self.inventory_adj_count = len(self.stock_adjustment_ids) + for rec in self: + rec.inventory_adj_count = len(rec.stock_adjustment_ids) @api.model def create(self, vals): @@ -52,14 +53,14 @@ class StockCycleCount(models.Model): inverse_name='cycle_count_id', string='Inventory Adjustment', track_visibility='onchange') - inventory_adj_count = fields.Integer(compute=_count_inventory_adj) + inventory_adj_count = fields.Integer(compute='_count_inventory_adj') company_id = fields.Many2one( comodel_name='res.company', string='Company', required=True, default=_company_get, readonly=True) - @api.one + @api.multi def do_cancel(self): - self.state = 'cancelled' + self.write({'state': 'cancelled'}) @api.model def _prepare_inventory_adjustment(self): @@ -70,15 +71,16 @@ class StockCycleCount(models.Model): 'exclude_sublocation': True } - @api.one + @api.multi def action_create_inventory_adjustment(self): - if self.state != 'draft': + if any([s != 'draft' for s in self.mapped('state')]): raise UserError(_( "You can only confirm cycle counts in state 'Planned'." )) - data = self._prepare_inventory_adjustment() - self.env['stock.inventory'].create(data) - self.state = 'open' + for rec in self: + data = rec._prepare_inventory_adjustment() + self.env['stock.inventory'].create(data) + self.write({'state': 'open'}) return True @api.multi @@ -86,11 +88,9 @@ class StockCycleCount(models.Model): action = self.env.ref('stock.action_inventory_form') result = action.read()[0] result['context'] = {} - adjustment_ids = sum([cycle_count.stock_adjustment_ids.ids - for cycle_count in self], []) + adjustment_ids = self.mapped('stock_adjustment_ids').ids if len(adjustment_ids) > 1: - result['domain'] = \ - "[('id','in',[" + ','.join(map(str, adjustment_ids)) + "])]" + result['domain'] = [('id', 'in', adjustment_ids)] elif len(adjustment_ids) == 1: res = self.env.ref('stock.view_inventory_form', False) result['views'] = [(res and res.id or False, 'form')] diff --git a/stock_cycle_count/models/stock_cycle_count_rule.py b/stock_cycle_count/models/stock_cycle_count_rule.py index 6a952ce8c..96a551a3f 100644 --- a/stock_cycle_count/models/stock_cycle_count_rule.py +++ b/stock_cycle_count/models/stock_cycle_count_rule.py @@ -3,9 +3,9 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models, _ -from openerp.exceptions import UserError -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo import api, fields, models, _ +from odoo.exceptions import UserError +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from datetime import timedelta, datetime @@ -83,7 +83,7 @@ class StockCycleCountRule(models.Model): """Get the warehouses for the selected locations.""" wh_ids = [] for loc in self.location_ids: - wh_ids.append(loc.get_warehouse(loc)) + wh_ids.append(loc.get_warehouse().id) wh_ids = list(set(wh_ids)) self.warehouse_ids = self.env['stock.warehouse'].browse(wh_ids) @@ -92,7 +92,7 @@ class StockCycleCountRule(models.Model): string='Type of rule', required=True) rule_description = fields.Char(string='Rule Description', - compute=_get_rule_description) + compute='_get_rule_description') active = fields.Boolean(string='Active', default=True) periodic_qty_per_period = fields.Integer(string='Counts per period', default=1) @@ -101,7 +101,7 @@ class StockCycleCountRule(models.Model): string='Turnover Inventory Value Threshold') currency_id = fields.Many2one(comodel_name='res.currency', string='Currency', - compute=_compute_currency) + compute='_compute_currency') accuracy_threshold = fields.Float(string='Minimum Accuracy Threshold', digits=(3, 2)) apply_in = fields.Selection( @@ -175,7 +175,7 @@ class StockCycleCountRule(models.Model): @api.model def _compute_turnover(self, move): - price = move.get_price_unit(move) + price = move.get_price_unit() turnover = move.product_uom_qty * price return turnover diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py index f4aad364a..b3788c077 100644 --- a/stock_cycle_count/models/stock_inventory.py +++ b/stock_cycle_count/models/stock_inventory.py @@ -3,8 +3,8 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models, _ -from openerp.exceptions import UserError +from odoo import api, fields, models, _ +from odoo.exceptions import UserError PERCENT = 100.0 @@ -29,9 +29,9 @@ class StockInventory(models.Model): cycle_count_id = fields.Many2one( comodel_name='stock.cycle.count', string='Stock Cycle Count', - ondelete='cascade', readonly=True) + ondelete='restrict', readonly=True) inventory_accuracy = fields.Float( - string='Accuracy', compute=_compute_inventory_accuracy, + string='Accuracy', compute='_compute_inventory_accuracy', digits=(3, 2), store=True, group_operator="avg") @api.multi diff --git a/stock_cycle_count/models/stock_location.py b/stock_cycle_count/models/stock_location.py index bf040984a..23130e0da 100644 --- a/stock_cycle_count/models/stock_location.py +++ b/stock_cycle_count/models/stock_location.py @@ -5,8 +5,8 @@ import logging -from openerp import api, fields, models, tools -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo import api, fields, models, tools +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from datetime import datetime _logger = logging.getLogger(__name__) @@ -26,8 +26,7 @@ class StockLocation(models.Model): ('location_id', '=', self.id), ('state', '=', 'done')]) history = history.sorted(key=lambda r: r.write_date, reverse=True) if history: - wh_id = self.get_warehouse(self) - wh = self.env['stock.warehouse'].browse(wh_id) + wh = self.get_warehouse() if len(history) > wh.counts_for_accuracy_qty: self.loc_accuracy = mean(history[:wh.counts_for_accuracy_qty]. mapped('inventory_accuracy')) @@ -47,9 +46,9 @@ class StockLocation(models.Model): qty_variance_inventory_threshold = fields.Float('Acceptable Inventory ' 'Quantity Variance ' 'Threshold') - loc_accuracy = fields.Float(string='Inventory Accuracy', - compute=_compute_loc_accuracy, - digits=(3, 2)) + loc_accuracy = fields.Float( + string='Inventory Accuracy', compute='_compute_loc_accuracy', + digits=(3, 2)) @api.model def _get_zero_confirmation_domain(self): @@ -59,8 +58,7 @@ class StockLocation(models.Model): @api.one def check_zero_confirmation(self): if not self.zero_confirmation_disabled: - wh_id = self.get_warehouse(self) - wh = self.env['stock.warehouse'].browse(wh_id) + wh = self.get_warehouse() rule_model = self.env['stock.cycle.count.rule'] zero_rule = rule_model.search([ ('rule_type', '=', 'zero'), @@ -73,9 +71,8 @@ class StockLocation(models.Model): def create_zero_confirmation_cycle_count(self): date = datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT) - wh_id = self.get_warehouse(self) - date_horizon = self.env['stock.warehouse'].browse( - wh_id).get_horizon_date()[0].strftime( + wh_id = self.get_warehouse().id + date_horizon = self.get_warehouse().get_horizon_date()[0].strftime( DEFAULT_SERVER_DATETIME_FORMAT) counts_planned = self.env['stock.cycle.count'].search([ ('date_deadline', '<', date_horizon), ('state', '=', 'draft'), diff --git a/stock_cycle_count/models/stock_move.py b/stock_cycle_count/models/stock_move.py index 302810ba1..184f427d8 100644 --- a/stock_cycle_count/models/stock_move.py +++ b/stock_cycle_count/models/stock_move.py @@ -3,7 +3,7 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, models +from odoo import api, models class StockMove(models.Model): diff --git a/stock_cycle_count/models/stock_warehouse.py b/stock_cycle_count/models/stock_warehouse.py index 453045b29..cd2942b81 100644 --- a/stock_cycle_count/models/stock_warehouse.py +++ b/stock_cycle_count/models/stock_warehouse.py @@ -3,9 +3,12 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo import api, fields, models +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from datetime import datetime, timedelta +import logging + +_logger = logging.getLogger(__name__) class StockWarehouse(models.Model): @@ -13,8 +16,7 @@ class StockWarehouse(models.Model): cycle_count_rule_ids = fields.Many2many( comodel_name='stock.cycle.count.rule', - relation='warehouse_cycle_count_' - 'rule_rel', + relation='warehouse_cycle_count_rule_rel', column1='warehouse_id', column2='rule_id', string='Cycle Count Rules') @@ -113,6 +115,13 @@ class StockWarehouse(models.Model): @api.model def cron_cycle_count(self): - whs = self.search([]) - whs.action_compute_cycle_count_rules() + _logger.info("stock_cycle_count cron job started.") + try: + whs = self.search([]) + whs.action_compute_cycle_count_rules() + except: + _logger.info( + "An error raised while running stock_cycle_count cron job.") + raise + _logger.info("stock_cycle_count cron job ended.") return True diff --git a/stock_cycle_count/reports/report_stock_location_accuracy.py b/stock_cycle_count/reports/report_stock_location_accuracy.py index 6b14a2a2a..e0c15bce0 100644 --- a/stock_cycle_count/reports/report_stock_location_accuracy.py +++ b/stock_cycle_count/reports/report_stock_location_accuracy.py @@ -3,7 +3,7 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import api, models +from odoo import api, models class LocationAccuracyReport(models.AbstractModel): diff --git a/stock_cycle_count/tests/__init__.py b/stock_cycle_count/tests/__init__.py index 31b8b678b..fc02bc8cf 100644 --- a/stock_cycle_count/tests/__init__.py +++ b/stock_cycle_count/tests/__init__.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import test_stock_cycle_count diff --git a/stock_cycle_count/tests/test_stock_cycle_count.py b/stock_cycle_count/tests/test_stock_cycle_count.py index b1e9c1888..86bbbf64b 100644 --- a/stock_cycle_count/tests/test_stock_cycle_count.py +++ b/stock_cycle_count/tests/test_stock_cycle_count.py @@ -2,9 +2,9 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp.tests import common -from openerp.exceptions import ValidationError -from openerp.exceptions import AccessError +from odoo.tests import common +from odoo.exceptions import ValidationError +from odoo.exceptions import AccessError from datetime import datetime, timedelta 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 1b4fb66af..60a65799c 100644 --- a/stock_cycle_count/views/stock_cycle_count_rule_view.xml +++ b/stock_cycle_count/views/stock_cycle_count_rule_view.xml @@ -48,7 +48,7 @@ - +

You can apply the cycle count rules in complete warehouses or specific zones. A zone it is understood as a location and all its children.

@@ -57,7 +57,9 @@ "Exclude from Cycle Count".

- +
diff --git a/stock_cycle_count/views/stock_cycle_count_view.xml b/stock_cycle_count/views/stock_cycle_count_view.xml index 9d544ee1e..50fa6f678 100644 --- a/stock_cycle_count/views/stock_cycle_count_view.xml +++ b/stock_cycle_count/views/stock_cycle_count_view.xml @@ -135,7 +135,7 @@ ir.actions.server code - self.action_create_inventory_adjustment(cr, uid, context.get('active_ids', []), context=context) + records.action_create_inventory_adjustment() diff --git a/stock_cycle_count/views/stock_location_view.xml b/stock_cycle_count/views/stock_location_view.xml index 71ef6cced..be97d45f8 100644 --- a/stock_cycle_count/views/stock_location_view.xml +++ b/stock_cycle_count/views/stock_location_view.xml @@ -15,14 +15,16 @@ context="{'location_id': active_ids}" type="object"/> - - - - + + + + + + diff --git a/stock_cycle_count/views/stock_warehouse_view.xml b/stock_cycle_count/views/stock_warehouse_view.xml index 26c7a6167..ada2568ea 100644 --- a/stock_cycle_count/views/stock_warehouse_view.xml +++ b/stock_cycle_count/views/stock_warehouse_view.xml @@ -30,7 +30,7 @@ ir.actions.server code - self.action_compute_cycle_count_rules(cr, uid, context.get('active_ids', []), context=context) + records.action_compute_cycle_count_rules()