diff --git a/project_stock/i18n/it.po b/project_stock/i18n/it.po index 7c9ede427a..2e0a3ebff6 100644 --- a/project_stock/i18n/it.po +++ b/project_stock/i18n/it.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2024-06-14 17:43+0000\n" +"PO-Revision-Date: 2023-12-18 10:34+0000\n" "Last-Translator: mymage \n" "Language-Team: none\n" "Language: it\n" @@ -132,7 +132,7 @@ msgstr "Movimenti di magazzino eseguiti" #. module: project_stock #: model_terms:ir.ui.view,arch_db:project_stock.view_stock_move_raw_tree msgid "Forecasted Report" -msgstr "Resoconto previsto" +msgstr "" #. module: project_stock #: model:ir.model.fields,field_description:project_stock.field_project_task__group_id diff --git a/project_stock/migrations/16.0.1.0.0/post-migration.py b/project_stock/migrations/16.0.1.0.0/post-migration.py deleted file mode 100644 index d185b63f4d..0000000000 --- a/project_stock/migrations/16.0.1.0.0/post-migration.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - """If table exists and there are any records, we set the module - project_stock_analytic_tag to be installed.""" - if openupgrade.table_exists(env.cr, "account_analytic_tag_project_task_stock_rel"): - env.cr.execute( - """SELECT COUNT(*) - FROM account_analytic_tag_project_task_stock_rel""", - ) - if env.cr.fetchone()[0]: - openupgrade.logged_query( - env.cr, - """UPDATE ir_module_module - SET state = 'to install' - WHERE name = 'project_stock_analytic_tag'""", - ) diff --git a/project_stock/models/project_task.py b/project_stock/models/project_task.py index eafc407c1c..81a7cc4a10 100644 --- a/project_stock/models/project_task.py +++ b/project_stock/models/project_task.py @@ -44,9 +44,7 @@ class ProjectTask(models.Model): comodel_name="stock.picking.type", string="Operation Type", readonly=False, - domain="[('company_id', '=', company_id)]", index=True, - check_company=True, ) location_id = fields.Many2one( comodel_name="stock.location", @@ -63,11 +61,6 @@ class ProjectTask(models.Model): check_company=True, ) stock_analytic_date = fields.Date(string="Analytic date") - unreserve_visible = fields.Boolean( - string="Allowed to Unreserve Inventory", - compute="_compute_unreserve_visible", - help="Technical field to check when we can unreserve", - ) stock_analytic_account_id = fields.Many2one( comodel_name="account.analytic.account", string="Move Analytic Account", @@ -86,6 +79,7 @@ class ProjectTask(models.Model): group_id = fields.Many2one( comodel_name="procurement.group", ) + company_id = fields.Many2one(default=lambda self: self.env.company) def _compute_scrap_move_count(self): data = self.env["stock.scrap"].read_group( @@ -121,13 +115,6 @@ def _compute_stock_state(self): task.stock_state = state break - @api.depends("move_ids", "move_ids.quantity_done") - def _compute_unreserve_visible(self): - for item in self: - already_reserved = item.mapped("move_ids.move_line_ids") - any_quantity_done = any([m.quantity_done > 0 for m in item.move_ids]) - item.unreserve_visible = not any_quantity_done and already_reserved - @api.onchange("picking_type_id") def _onchange_picking_type_id(self): self.location_id = self.picking_type_id.default_location_src_id.id @@ -166,7 +153,10 @@ def _prepare_procurement_group_vals(self): return {"name": "Task-ID: %s" % self.id} def action_confirm(self): - self.mapped("move_ids")._action_confirm() + self.move_ids._action_confirm() + self.move_ids.filtered( + lambda move: move.state not in ("draft", "cancel", "done") + )._trigger_scheduler() def action_assign(self): self.action_confirm() @@ -189,23 +179,11 @@ def button_scrap(self): "target": "new", } - def do_unreserve(self): - for item in self: - item.move_ids.filtered( - lambda x: x.state not in ("done", "cancel") - )._do_unreserve() - return True - - def button_unreserve(self): - self.ensure_one() - self.do_unreserve() - return True - def action_cancel(self): """Cancel the stock moves and remove the analytic lines created from stock moves when cancelling the task. """ - self.mapped("move_ids.move_line_ids").write({"qty_done": 0}) + self.mapped("move_ids.move_line_ids").write({"quantity": 0}) # Use sudo to avoid error for users with no access to analytic self.sudo().stock_analytic_line_ids.unlink() self.stock_moves_is_locked = True @@ -217,15 +195,12 @@ def action_toggle_stock_moves_is_locked(self): return True def action_done(self): - # Filter valid stock moves (avoiding those done and cancelled). - for move in self.mapped("move_ids").filtered( - lambda x: x.state not in ("done", "cancel") - ): - move.quantity_done = move.reserved_availability - moves_todo = self.mapped("move_ids")._action_done() + picking_ids = self.move_ids.picking_id + for picking in picking_ids: + picking.with_context(skip_sanity_check=True).button_validate() # Use sudo to avoid error for users with no access to analytic analytic_line_model = self.env["account.analytic.line"].sudo() - for move in moves_todo: + for move in self.move_ids: vals = move._prepare_analytic_line_from_task() if vals: analytic_line_model.create(vals) diff --git a/project_stock/models/stock_move.py b/project_stock/models/stock_move.py index 22657db3ac..406c218246 100644 --- a/project_stock/models/stock_move.py +++ b/project_stock/models/stock_move.py @@ -40,7 +40,7 @@ def _prepare_analytic_line_from_task(self): or fields.date.today() ), "name": task.name + ": " + product.name, - "unit_amount": self.quantity_done, + "unit_amount": self.quantity, "account_id": analytic_account.id, "user_id": self._uid, "product_uom_id": self.product_uom.id, @@ -48,10 +48,10 @@ def _prepare_analytic_line_from_task(self): "partner_id": task.partner_id.id or task.project_id.partner_id.id or False, "stock_task_id": task.id, } - amount_unit = product.with_context(uom=self.product_uom.id).price_compute( + amount_unit = product.with_context(uom=self.product_uom.id)._price_compute( "standard_price" )[product.id] - amount = amount_unit * self.quantity_done or 0.0 + amount = amount_unit * self.quantity or 0.0 result = round(amount, company_id.currency_id.decimal_places) * -1 vals = {"amount": result} analytic_line_fields = self.env["account.analytic.line"]._fields diff --git a/project_stock/tests/common.py b/project_stock/tests/common.py index 1eb846ff65..4ee8a6ea2f 100644 --- a/project_stock/tests/common.py +++ b/project_stock/tests/common.py @@ -27,7 +27,6 @@ def setUpClass(cls): cls.plan = cls.env["account.analytic.plan"].create( { "name": "Projects Plan", - "company_id": False, } ) cls.analytic_account = cls.env["account.analytic.account"].create( diff --git a/project_stock/tests/test_project_stock.py b/project_stock/tests/test_project_stock.py index 3428d562d1..09f4b0102f 100644 --- a/project_stock/tests/test_project_stock.py +++ b/project_stock/tests/test_project_stock.py @@ -41,13 +41,11 @@ def test_project_task_misc(self): self.assertEqual(self.task.location_id, self.location) self.assertEqual(self.task.location_dest_id, self.location_dest) self.assertEqual(self.move_product_a.name, self.task.name) - self.assertEqual(self.move_product_a.group_id, self.task.group_id) self.assertEqual(self.move_product_a.reference, self.task.name) self.assertEqual(self.move_product_a.location_id, self.location) self.assertEqual(self.move_product_a.location_dest_id, self.location_dest) self.assertEqual(self.move_product_a.picking_type_id, self.picking_type) self.assertEqual(self.move_product_a.raw_material_task_id, self.task) - self.assertEqual(self.move_product_b.group_id, self.task.group_id) self.assertEqual(self.move_product_b.location_id, self.location) self.assertEqual(self.move_product_b.location_dest_id, self.location_dest) self.assertEqual(self.move_product_b.picking_type_id, self.picking_type) @@ -151,8 +149,8 @@ def test_project_task_process_done(self): self.task.write({"stage_id": self.stage_done.id}) self.assertEqual(self.move_product_a.state, "assigned") self.assertEqual(self.move_product_b.state, "assigned") - self.assertEqual(self.move_product_a.reserved_availability, 2) - self.assertEqual(self.move_product_b.reserved_availability, 1) + self.assertEqual(self.move_product_a.quantity, 2) + self.assertEqual(self.move_product_b.quantity, 1) self.assertTrue(self.task.stock_moves_is_locked) self.task.action_toggle_stock_moves_is_locked() self.assertFalse(self.task.stock_moves_is_locked) @@ -166,7 +164,6 @@ def test_project_task_process_done(self): move_product_c = self.task.move_ids.filtered( lambda x: x.product_id == self.product_c ) - self.assertEqual(move_product_c.group_id, self.task.group_id) self.assertEqual(move_product_c.state, "draft") self.task.action_assign() self.assertEqual(move_product_c.state, "assigned") @@ -175,9 +172,9 @@ def test_project_task_process_done(self): self.task.action_done() self.assertEqual(self.move_product_a.state, "done") self.assertEqual(self.move_product_b.state, "done") - self.assertEqual(self.move_product_a.quantity_done, 2) - self.assertEqual(self.move_product_b.quantity_done, 1) - self.assertEqual(move_product_c.quantity_done, 1) + self.assertEqual(self.move_product_a.quantity, 2) + self.assertEqual(self.move_product_b.quantity, 1) + self.assertEqual(move_product_c.quantity, 1) @users("basic-user") def test_project_task_process_done_basic_user(self): @@ -196,15 +193,15 @@ def test_project_task_process_cancel(self): self.task.action_done() self.assertEqual(self.move_product_a.state, "done") self.assertEqual(self.move_product_b.state, "done") - self.assertEqual(self.move_product_a.quantity_done, 2) - self.assertEqual(self.move_product_b.quantity_done, 1) + self.assertEqual(self.move_product_a.quantity, 2) + self.assertEqual(self.move_product_b.quantity, 1) self.assertTrue(self.task.sudo().stock_analytic_line_ids) # action_cancel self.task.action_cancel() self.assertEqual(self.move_product_a.state, "done") self.assertEqual(self.move_product_b.state, "done") - self.assertEqual(self.move_product_a.quantity_done, 0) - self.assertEqual(self.move_product_b.quantity_done, 0) + self.assertEqual(self.move_product_a.quantity, 0) + self.assertEqual(self.move_product_b.quantity, 0) self.assertFalse(self.task.stock_analytic_line_ids) quant_a = self.product_a.stock_quant_ids.filtered( lambda x: x.location_id == self.location @@ -223,28 +220,6 @@ def test_project_task_process_cancel(self): def test_project_task_process_cancel_manager_user(self): self.test_project_task_process_cancel() - @mute_logger("odoo.models.unlink") - def test_project_task_process_unreserve(self): - self.task = self.env["project.task"].browse(self.task.id) - self.assertEqual(self.move_product_a.state, "draft") - self.assertEqual(self.move_product_b.state, "draft") - # Change task stage (auto-confirm + auto-assign) - self.task.write({"stage_id": self.stage_done.id}) - self.assertTrue(self.move_product_a.move_line_ids) - self.assertEqual(self.move_product_a.move_line_ids.task_id, self.task) - self.assertEqual(self.move_product_a.state, "assigned") - self.assertEqual(self.move_product_b.state, "assigned") - self.assertEqual(self.move_product_a.reserved_availability, 2) - self.assertEqual(self.move_product_b.reserved_availability, 1) - self.assertTrue(self.task.unreserve_visible) - # button_unreserve - self.task.button_unreserve() - self.assertEqual(self.move_product_a.state, "confirmed") - self.assertEqual(self.move_product_b.state, "confirmed") - self.assertEqual(self.move_product_a.reserved_availability, 0) - self.assertEqual(self.move_product_b.reserved_availability, 0) - self.assertFalse(self.task.unreserve_visible) - @mute_logger("odoo.models.unlink") def test_project_task_process_01(self): """Product A move cancel + Product B move OK.""" @@ -280,11 +255,6 @@ def test_project_task_process_02(self): self.assertEqual(self.move_product_b.state, "done") self.assertEqual(len(self.task.stock_analytic_line_ids), 2) self.task.action_done() - self.assertEqual(len(self.task.stock_analytic_line_ids), 2) - - @users("basic-user") - def test_project_task_process_unreserve_basic_user(self): - self.test_project_task_process_unreserve() def test_project_task_action_cancel(self): self.assertTrue(self.env["project.task"].browse(self.task.id).action_cancel()) @@ -320,11 +290,6 @@ def test_project_project_onchange(self): self.assertEqual( self.project.location_dest_id, new_type.default_location_dest_id ) - self.task.do_unreserve() - self.task.write({"picking_type_id": new_type.id}) - self.task._onchange_picking_type_id() - self.assertEqual(self.task.location_id, new_type.default_location_src_id) - self.assertEqual(self.task.location_dest_id, new_type.default_location_dest_id) move = fields.first(self.task.move_ids) self.assertEqual(move.location_id, new_type.default_location_src_id) @@ -339,4 +304,4 @@ def test_project_task_scrap(self): } ) scrap.do_scrap() - self.assertEqual(scrap.move_id.raw_material_task_id, self.task) + self.assertEqual(scrap.move_ids.raw_material_task_id, self.task) diff --git a/project_stock/views/project_project_view.xml b/project_stock/views/project_project_view.xml index 9aa8ffa3c8..2d97ba2685 100644 --- a/project_stock/views/project_project_view.xml +++ b/project_stock/views/project_project_view.xml @@ -7,7 +7,7 @@ - + - + diff --git a/project_stock/views/project_task_view.xml b/project_stock/views/project_task_view.xml index 0f5395c3e2..844934da23 100644 --- a/project_stock/views/project_task_view.xml +++ b/project_stock/views/project_task_view.xml @@ -12,7 +12,7 @@ string="Product Moves" class="oe_stat_button" icon="fa-exchange" - attrs="{'invisible': [('done_stock_moves', '=', False)]}" + invisible="not done_stock_moves" groups="stock.group_stock_user" /> - + - +