Skip to content

Commit

Permalink
[MIG] project_stock: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoc-exo committed Jun 26, 2024
1 parent 64d9e59 commit 243d729
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 147 deletions.
4 changes: 2 additions & 2 deletions project_stock/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
Expand Down Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions project_stock/migrations/16.0.1.0.0/post-migration.py

This file was deleted.

40 changes: 6 additions & 34 deletions project_stock/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -189,23 +176,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
Expand All @@ -217,15 +192,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)
Expand Down
6 changes: 3 additions & 3 deletions project_stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ 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,
"company_id": analytic_account.company_id.id or self.env.company.id,
"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
Expand Down
45 changes: 9 additions & 36 deletions project_stock/tests/test_project_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,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)
Expand All @@ -175,9 +175,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):
Expand All @@ -196,15 +196,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
Expand All @@ -223,28 +223,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."""
Expand Down Expand Up @@ -282,10 +260,6 @@ def test_project_task_process_02(self):
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())

Expand Down Expand Up @@ -320,7 +294,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)
Expand Down
2 changes: 1 addition & 1 deletion project_stock/views/project_project_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="arch" type="xml">
<xpath expr="///group[@name='extra_settings']" position="before">
<group string="Stock" name="stock_misc" groups="stock.group_stock_user">
<field name="picking_type_id" />
<field name="picking_type_id" domain="[]" />
<field
name="location_id"
groups="stock.group_stock_multi_locations"
Expand Down
5 changes: 1 addition & 4 deletions project_stock/views/project_task_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<field name="arch" type="xml">
<field name="fold" position="after">
<field name="use_stock_moves" />
<field
name="done_stock_moves"
attrs="{'invisible': [('use_stock_moves', '=', False)]}"
/>
<field name="done_stock_moves" invisible="not use_stock_moves" />
</field>
</field>
</record>
Expand Down
Loading

0 comments on commit 243d729

Please sign in to comment.