diff --git a/stock_cycle_count/README.rst b/stock_cycle_count/README.rst index 7cd4c844b..5e64625f6 100644 --- a/stock_cycle_count/README.rst +++ b/stock_cycle_count/README.rst @@ -2,10 +2,13 @@ Stock Cycle Count ================= -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b64525365fd22f8fc11eb092a90920c9ee433c721991ce7c36c55a5b72f77373 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status @@ -14,16 +17,16 @@ Stock Cycle Count :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_cycle_count + :target: https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_cycle_count :alt: OCA/stock-logistics-warehouse .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_cycle_count + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_cycle_count :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/153/14.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=15.0 + :alt: Try me on Runboat -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| 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 @@ -126,8 +129,8 @@ 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 smashing it by providing a detailed and welcomed -`feedback `_. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -168,6 +171,6 @@ Current `maintainer `__: |maintainer-LoisRForgeFlow| -This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_cycle_count/__manifest__.py b/stock_cycle_count/__manifest__.py index e60be739b..ae2da5b1f 100644 --- a/stock_cycle_count/__manifest__.py +++ b/stock_cycle_count/__manifest__.py @@ -5,7 +5,7 @@ "name": "Stock Cycle Count", "summary": "Adds the capability to schedule cycle counts in a " "warehouse through different rules defined by the user.", - "version": "14.0.1.4.0", + "version": "15.0.1.0.0", "maintainers": ["LoisRForgeFlow"], "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", diff --git a/stock_cycle_count/models/__init__.py b/stock_cycle_count/models/__init__.py index d479160f3..e1320941d 100644 --- a/stock_cycle_count/models/__init__.py +++ b/stock_cycle_count/models/__init__.py @@ -1,8 +1,8 @@ +from . import res_company +from . import res_config_settings from . import stock_cycle_count from . import stock_cycle_count_rule from . import stock_location from . import stock_inventory from . import stock_warehouse from . import stock_move -from . import res_company -from . import res_config_settings diff --git a/stock_cycle_count/models/res_config_settings.py b/stock_cycle_count/models/res_config_settings.py index 884f5c245..05bb6cc17 100644 --- a/stock_cycle_count/models/res_config_settings.py +++ b/stock_cycle_count/models/res_config_settings.py @@ -16,10 +16,6 @@ class ResConfigSettings(models.TransientModel): inventory_adjustment_counted_quantities = fields.Selection( related="company_id.inventory_adjustment_counted_quantities", - selection=[ - ("counted", "Default to stock on hand"), - ("zero", "Default to zero"), - ], string="Inventory Adjustment Counted quantities from Cycle Count", help="If enabled, confirming a Cycle Count will start the related " "Inventory Adjustment.", diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py index 57e0484c8..ea373c2a3 100644 --- a/stock_cycle_count/models/stock_cycle_count.py +++ b/stock_cycle_count/models/stock_cycle_count.py @@ -12,7 +12,7 @@ class StockCycleCount(models.Model): _inherit = "mail.thread" _order = "id desc" - name = fields.Char(string="Name", readonly=True) + name = fields.Char(readonly=True) location_id = fields.Many2one( comodel_name="stock.location", string="Location", @@ -48,7 +48,6 @@ class StockCycleCount(models.Model): ("cancelled", "Cancelled"), ("done", "Done"), ], - string="State", default="draft", tracking=True, ) @@ -100,20 +99,25 @@ class StockCycleCount(models.Model): inv.prefill_counted_quantity = ( self.company_id.inventory_adjustment_counted_quantities ) - inv.action_start() + inv.action_state_to_in_progress() + if inv.prefill_counted_quantity == "zero": + inv.stock_quant_ids.write({"inventory_quantity": 0}) + else: + for quant in inv.stock_quant_ids: + quant.write({"inventory_quantity": quant.quantity}) self.write({"state": "open"}) return True def action_view_inventory(self): - action = self.env["ir.actions.act_window"]._for_xml_id( - "stock.action_inventory_form" - ) + action = self.env.ref( + "stock_inventory.action_view_inventory_group_form" + ).read()[0] action["context"] = {} adjustment_ids = self.mapped("stock_adjustment_ids").ids if len(adjustment_ids) > 1: action["domain"] = [("id", "in", adjustment_ids)] elif len(adjustment_ids) == 1: - res = self.env.ref("stock.view_inventory_form", False) + res = self.env.ref("stock_inventory.view_inventory_group_form", False) action["views"] = [(res and res.id or False, "form")] action["res_id"] = adjustment_ids and adjustment_ids[0] or False return action diff --git a/stock_cycle_count/models/stock_cycle_count_rule.py b/stock_cycle_count/models/stock_cycle_count_rule.py index 6e3a0340d..30ee41d0b 100644 --- a/stock_cycle_count/models/stock_cycle_count_rule.py +++ b/stock_cycle_count/models/stock_cycle_count_rule.py @@ -99,23 +99,20 @@ 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().id) + wh_ids.append(loc.warehouse_id.id) wh_ids = list(set(wh_ids)) + wh_ids = [wh for wh in wh_ids if wh] self.warehouse_ids = self.env["stock.warehouse"].browse(wh_ids) name = fields.Char(required=True) rule_type = fields.Selection( selection="_selection_rule_types", string="Type of rule", required=True ) - rule_description = fields.Char( - string="Rule Description", compute="_compute_rule_description" - ) + rule_description = fields.Char(compute="_compute_rule_description") active = fields.Boolean(default=True) periodic_qty_per_period = fields.Integer(string="Counts per period", default=1) periodic_count_period = fields.Integer(string="Period in days") - turnover_inventory_value_threshold = fields.Float( - string="Turnover Inventory Value Threshold" - ) + turnover_inventory_value_threshold = fields.Float() currency_id = fields.Many2one( comodel_name="res.currency", string="Currency", compute="_compute_currency_id" ) @@ -194,7 +191,7 @@ class StockCycleCountRule(models.Model): "cycle count rule. %s" ) % str(e) - ) + ) from e else: next_date = datetime.today() cycle_count = self._propose_cycle_count(next_date, loc) @@ -254,7 +251,7 @@ class StockCycleCountRule(models.Model): "rule threshold. %s" ) % str(e) - ) + ) from e else: next_date = datetime.today() cycle_count = self._propose_cycle_count(next_date, loc) diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py index b0b804246..e38ff1656 100644 --- a/stock_cycle_count/models/stock_inventory.py +++ b/stock_cycle_count/models/stock_inventory.py @@ -11,18 +11,39 @@ PERCENT = 100.0 class StockInventory(models.Model): _inherit = "stock.inventory" - @api.depends("state", "line_ids") + @api.depends("state", "stock_quant_ids") def _compute_inventory_accuracy(self): for inv in self: - theoretical = sum(inv.line_ids.mapped(lambda x: abs(x.theoretical_qty))) - abs_discrepancy = sum(inv.line_ids.mapped(lambda x: abs(x.discrepancy_qty))) + theoretical = sum(inv.stock_quant_ids.mapped(lambda x: abs(x.quantity))) + abs_discrepancy = sum( + inv.stock_quant_ids.mapped(lambda x: abs(x.inventory_diff_quantity)) + ) if theoretical: inv.inventory_accuracy = max( PERCENT * (theoretical - abs_discrepancy) / theoretical, 0.0 ) - if not inv.line_ids and inv.state == "done": + if not inv.stock_quant_ids and inv.state == "done": inv.inventory_accuracy = PERCENT + company_id = fields.Many2one( + "res.company", + "Company", + readonly=True, + index=True, + required=True, + states={"draft": [("readonly", False)]}, + default=lambda self: self.env.company, + ) + prefill_counted_quantity = fields.Selection( + string="Counted Quantities", + help="Allows to start with a pre-filled counted quantity for each lines or " + "with all counted quantities set to zero.", + default="counted", + selection=[ + ("counted", "Default to stock on hand"), + ("zero", "Default to zero"), + ], + ) cycle_count_id = fields.Many2one( comodel_name="stock.cycle.count", string="Stock Cycle Count", @@ -47,7 +68,14 @@ class StockInventory(models.Model): return company_id.inventory_adjustment_counted_quantities or "counted" prefill_counted_quantity = fields.Selection( - default=_get_default_counted_quantitites + string="Counted Quantities", + help="Allows to start with a pre-filled counted quantity for each lines or " + "with all counted quantities set to zero.", + default=_get_default_counted_quantitites, + selection=[ + ("counted", "Default to stock on hand"), + ("zero", "Default to zero"), + ], ) def _update_cycle_state(self): @@ -84,8 +112,8 @@ class StockInventory(models.Model): self.write({"cycle_count_id": candidate.id, "exclude_sublocation": True}) return True - def action_validate(self): - res = super(StockInventory, self).action_validate() + def action_state_to_done(self): + res = super(StockInventory, self).action_state_to_done() self._update_cycle_state() return res diff --git a/stock_cycle_count/models/stock_location.py b/stock_cycle_count/models/stock_location.py index 1dd17dafd..9210ce52b 100644 --- a/stock_cycle_count/models/stock_location.py +++ b/stock_cycle_count/models/stock_location.py @@ -28,7 +28,7 @@ class StockLocation(models.Model): order="write_date desc", ) if history: - wh = rec.get_warehouse() + wh = rec.warehouse_id if ( wh.counts_for_accuracy_qty and len(history) > wh.counts_for_accuracy_qty @@ -68,7 +68,7 @@ class StockLocation(models.Model): def check_zero_confirmation(self): for rec in self: if not rec.zero_confirmation_disabled: - wh = rec.get_warehouse() + wh = rec.warehouse_id rule_model = self.env["stock.cycle.count.rule"] zero_rule = rule_model.search( [("rule_type", "=", "zero"), ("warehouse_ids", "=", wh.id)] @@ -83,11 +83,9 @@ class StockLocation(models.Model): def create_zero_confirmation_cycle_count(self): self.ensure_one() date = datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT) - wh_id = self.get_warehouse().id - date_horizon = ( - self.get_warehouse() - .get_horizon_date() - .strftime(DEFAULT_SERVER_DATETIME_FORMAT) + wh_id = self.warehouse_id.id + date_horizon = self.warehouse_id.get_horizon_date().strftime( + DEFAULT_SERVER_DATETIME_FORMAT ) counts_planned = self.env["stock.cycle.count"].search( [ diff --git a/stock_cycle_count/models/stock_warehouse.py b/stock_cycle_count/models/stock_warehouse.py index cbad86f08..75a392d7e 100644 --- a/stock_cycle_count/models/stock_warehouse.py +++ b/stock_cycle_count/models/stock_warehouse.py @@ -93,7 +93,7 @@ class StockWarehouse(models.Model): proposed_for_loc = list( filter(lambda x: x["location"] == loc, proposed_cycle_counts) ) - earliest_date = min([d["date"] for d in proposed_for_loc]) + earliest_date = min(d["date"] for d in proposed_for_loc) cycle_count_proposed = list( filter(lambda x: x["date"] == earliest_date, proposed_for_loc) )[0] diff --git a/stock_cycle_count/static/description/index.html b/stock_cycle_count/static/description/index.html index 74d4a2422..0d4e4e45a 100644 --- a/stock_cycle_count/static/description/index.html +++ b/stock_cycle_count/static/description/index.html @@ -1,20 +1,19 @@ - - + Stock Cycle Count