From f04dd9d965a5f2b25a0cc6b02d0c36ba8eb7258c Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 9 Mar 2017 15:54:32 +0100 Subject: [PATCH] [IMP] stock_cycle_count: * Update README. * Fixes: DEFAULT_SERVER_DATETIME_FORMAT, PERCENT variables and sale price calculation. --- stock_cycle_count/README.rst | 23 +++++++++++++++---- .../models/stock_cycle_count_rule.py | 9 +++++--- stock_cycle_count/models/stock_inventory.py | 6 +++-- stock_cycle_count/models/stock_location.py | 6 +++-- stock_cycle_count/models/stock_warehouse.py | 3 ++- .../tests/test_stock_cycle_count.py | 5 ++-- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/stock_cycle_count/README.rst b/stock_cycle_count/README.rst index b2a9cecb9..6f025e4ae 100644 --- a/stock_cycle_count/README.rst +++ b/stock_cycle_count/README.rst @@ -6,9 +6,22 @@ Stock Cycle Count ================= -This module adds the capability to execute a cycle count strategy in a -warehouse through different rules defined by the user. +This module provides the capability to execute a cycle count strategy in a +warehouse through different rules defined by the user. Cycle count is an +alternative to full wall-to-wall physical inventories in which little +portions (stock locations) of the stock are selected to count on a regular +basis. +The system propose locations in which to perform a inventory adjustment every +day based on a set of rules defined for the warehouse. In addition the system +can propose Zero-Confirmations which are simply and opportunistic counts to +check whether a locations has actually became empty or not. + +With this strategy it is possible to: +* Remove the need to perform full physical inventories and to stop the + production in the warehouse. +* Measure the accuracy of the inventory records and improve it. +* Correct inventory errors earlier and prevent them to become bigger. Installation ============ @@ -60,9 +73,9 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smash it by providing detailed and welcomed feedback. +`_. In case of +trouble, please check there if your issue has already been reported. If you +spotted it first, help us smash it by providing detailed and welcomed feedback. Images diff --git a/stock_cycle_count/models/stock_cycle_count_rule.py b/stock_cycle_count/models/stock_cycle_count_rule.py index 23008e1f2..a67c50161 100644 --- a/stock_cycle_count/models/stock_cycle_count_rule.py +++ b/stock_cycle_count/models/stock_cycle_count_rule.py @@ -5,6 +5,7 @@ from openerp import api, fields, models, _ from openerp.exceptions import UserError +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from datetime import timedelta, datetime @@ -111,7 +112,7 @@ class StockCycleCountRule(models.Model): @api.model def _propose_cycle_count(self, date, location): cycle_count = { - 'date': date.strftime('%Y-%m-%d %H:%M:%S'), + 'date': date.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'location': location, 'rule_type': self } @@ -130,7 +131,8 @@ class StockCycleCountRule(models.Model): period = self.periodic_count_period / \ self.periodic_qty_per_period next_date = datetime.strptime( - latest_inventory, '%Y-%m-%d %H:%M:%S') + timedelta( + latest_inventory, + DEFAULT_SERVER_DATETIME_FORMAT) + timedelta( days=period) except Exception as e: raise UserError( @@ -153,7 +155,8 @@ class StockCycleCountRule(models.Model): @api.model def _compute_turnover(self, move): - turnover = move.product_uom_qty * move.product_id.standard_price + price = move.get_price_unit(move) + turnover = move.product_uom_qty * price return turnover @api.model diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py index d01e09095..8dd027d25 100644 --- a/stock_cycle_count/models/stock_inventory.py +++ b/stock_cycle_count/models/stock_inventory.py @@ -5,6 +5,8 @@ from openerp import api, fields, models +PERCENT = 100.0 + class StockInventory(models.Model): _inherit = 'stock.inventory' @@ -15,8 +17,8 @@ class StockInventory(models.Model): abs_discrepancy = sum(self.line_ids.mapped( lambda x: abs(x.discrepancy_qty))) if total_qty: - self.inventory_accuracy = 100 * (total_qty - abs_discrepancy) / \ - total_qty + self.inventory_accuracy = PERCENT * ( + total_qty - abs_discrepancy) / total_qty if not self.line_ids and self.state == 'done': self.inventory_accuracy = 100.0 diff --git a/stock_cycle_count/models/stock_location.py b/stock_cycle_count/models/stock_location.py index b429bd90b..a9b5730c0 100644 --- a/stock_cycle_count/models/stock_location.py +++ b/stock_cycle_count/models/stock_location.py @@ -6,6 +6,7 @@ import logging from openerp import api, fields, models, tools +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from datetime import datetime _logger = logging.getLogger(__name__) @@ -71,10 +72,11 @@ class StockLocation(models.Model): self.create_zero_confirmation_cycle_count() def create_zero_confirmation_cycle_count(self): - date = datetime.today().strftime('%Y-%m-%d %H:%M:%S') + 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('%Y-%m-%d %H:%M:%S') + wh_id).get_horizon_date()[0].strftime( + DEFAULT_SERVER_DATETIME_FORMAT) counts_planned = self.env['stock.cycle.count'].search([ ('date_deadline', '<', date_horizon), ('state', '=', 'draft'), ('location_id', '=', self.id)]) diff --git a/stock_cycle_count/models/stock_warehouse.py b/stock_cycle_count/models/stock_warehouse.py index 89d36eae0..01afabdea 100644 --- a/stock_cycle_count/models/stock_warehouse.py +++ b/stock_cycle_count/models/stock_warehouse.py @@ -4,6 +4,7 @@ # 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 datetime import datetime, timedelta @@ -92,7 +93,7 @@ class StockWarehouse(models.Model): existing_cycle_counts.state = 'cancelled' delta = datetime.strptime( cycle_count_proposed['date'], - '%Y-%m-%d %H:%M:%S') - datetime.today() + DEFAULT_SERVER_DATETIME_FORMAT) - datetime.today() if not existing_cycle_counts and \ delta.days < self.cycle_count_planning_horizon: self.env['stock.cycle.count'].create({ diff --git a/stock_cycle_count/tests/test_stock_cycle_count.py b/stock_cycle_count/tests/test_stock_cycle_count.py index 751f3a107..e80f50cb5 100644 --- a/stock_cycle_count/tests/test_stock_cycle_count.py +++ b/stock_cycle_count/tests/test_stock_cycle_count.py @@ -67,7 +67,7 @@ class TestStockCycleCount(common.TransactionCase): self.stock_cycle_count1.action_view_inventory() self.inventory1 = self.stock_inventory_model.search([ - ('cycle_count_id', '=', self.stock_cycle_count1.id)]) + ('cycle_count_id', '=', self.stock_cycle_count1.id)]) self.inventory1.prepare_inventory() self.inventory1.action_done() @@ -167,4 +167,5 @@ class TestStockCycleCount(common.TransactionCase): # constrain: can only have one warehouse assigned self.stock_cycle_count_rule4.warehouse_ids = [(4, self.big_wh.id)] with self.assertRaises(ValidationError): - self.stock_cycle_count_rule4.warehouse_ids = [(4, self.small_wh.id)] + self.stock_cycle_count_rule4.warehouse_ids = [ + (4, self.small_wh.id)]