Skip to content

Commit

Permalink
[MIG] stock_analytic: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomacr committed Dec 15, 2022
1 parent 8f9ff25 commit f44fe3a
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 306 deletions.
7 changes: 4 additions & 3 deletions stock_analytic/__manifest__.py
Expand Up @@ -7,7 +7,7 @@
{
"name": "Stock Analytic",
"summary": "Adds an analytic account and analytic tags in stock move",
"version": "14.0.2.0.0",
"version": "16.0.1.0.0",
"author": "Julius Network Solutions, "
"ClearCorp, OpenSynergy Indonesia, "
"Hibou Corp., "
Expand All @@ -18,8 +18,9 @@
"depends": ["stock_account", "analytic"],
"data": [
"views/stock_move_views.xml",
"views/stock_scrap.xml",
"views/stock_move_line.xml",
"views/stock_scrap_views.xml",
"views/stock_move_line_views.xml",
"views/stock_picking_views.xml",
],
"installable": True,
}
29 changes: 0 additions & 29 deletions stock_analytic/migrations/14.0.2.0.0/pre-migrate.py

This file was deleted.

1 change: 0 additions & 1 deletion stock_analytic/models/__init__.py
@@ -1,5 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import product_product
from . import stock
from . import stock_scrap
44 changes: 0 additions & 44 deletions stock_analytic/models/product_product.py

This file was deleted.

48 changes: 16 additions & 32 deletions stock_analytic/models/stock.py
Expand Up @@ -5,38 +5,29 @@
# Copyright 2018 Hibou Corp.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

analytic_account_id = fields.Many2one(
string="Analytic Account",
comodel_name="account.analytic.account",
)
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
_name = "stock.move"
_inherit = ["stock.move", "analytic.mixin"]

def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id, description
self, qty, cost, credit_account_id, debit_account_id, svl_id, description
):
self.ensure_one()
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, description
qty, cost, credit_account_id, debit_account_id, svl_id, description
)
if not self.analytic_distribution:
return res
for line in res:
if (
line[2]["account_id"]
!= self.product_id.categ_id.property_stock_valuation_account_id.id
):
# Add analytic account in debit line
if self.analytic_account_id:
line[2].update({"analytic_account_id": self.analytic_account_id.id})
# Add analytic tags in debit line
if self.analytic_tag_ids:
line[2].update(
{"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)]}
)
line[2].update({"analytic_distribution": self.analytic_distribution})
return res

def _prepare_procurement_values(self):
Expand All @@ -45,20 +36,14 @@ def _prepare_procurement_values(self):
moves through procurement.
"""
res = super()._prepare_procurement_values()
if self.analytic_account_id:
if self.analytic_distribution:
res.update(
{
"analytic_account_id": self.analytic_account_id.id,
"analytic_distribution": self.analytic_distribution,
}
)
return res

@api.model
def _prepare_merge_moves_distinct_fields(self):
fields = super()._prepare_merge_moves_distinct_fields()
fields.append("analytic_account_id")
return fields

def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
"""
We fill in the analytic account when creating the move line from
Expand All @@ -67,15 +52,14 @@ def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
res = super()._prepare_move_line_vals(
quantity=quantity, reserved_quant=reserved_quant
)
if self.analytic_account_id:
res.update({"analytic_account_id": self.analytic_account_id.id})
if self.analytic_distribution:
res.update({"analytic_distribution": self.analytic_distribution})
return res


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

analytic_account_id = fields.Many2one(comodel_name="account.analytic.account")
_name = "stock.move.line"
_inherit = ["stock.move.line", "analytic.mixin"]

@api.model
def _prepare_stock_move_vals(self):
Expand All @@ -84,6 +68,6 @@ def _prepare_stock_move_vals(self):
new move created here with the analytic account if filled in.
"""
res = super()._prepare_stock_move_vals()
if self.analytic_account_id:
res.update({"analytic_account_id": self.analytic_account_id.id})
if self.analytic_distribution:
res.update({"analytic_distribution": self.analytic_distribution})
return res
13 changes: 4 additions & 9 deletions stock_analytic/models/stock_scrap.py
@@ -1,22 +1,17 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import models


class StockScrap(models.Model):
_inherit = "stock.scrap"

analytic_account_id = fields.Many2one(
string="Analytic Account", comodel_name="account.analytic.account"
)
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
_name = "stock.scrap"
_inherit = ["stock.scrap", "analytic.mixin"]

def _prepare_move_values(self):
res = super()._prepare_move_values()
res.update(
{
"analytic_account_id": self.analytic_account_id.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
"analytic_distribution": self.analytic_distribution,
}
)
return res
1 change: 1 addition & 0 deletions stock_analytic/readme/CONTRIBUTORS.rst
Expand Up @@ -8,3 +8,4 @@
* Aaron Henriquez <ahenriquez@forgeflow.com>
* Jared Kipe <jared@hibou.io>
* Alan Ramos <alan.ramos@jarsa.com.mx>
* Mantas Šniukas <mantas@vialaurea.lt>

0 comments on commit f44fe3a

Please sign in to comment.