-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] stock_request_analytic: Migration to 17.0
- Loading branch information
1 parent
b267d68
commit e495aae
Showing
15 changed files
with
99 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
stock_request_analytic/migrations/16.0.1.0.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from openupgradelib.openupgrade_160 import fill_analytic_distribution | ||
|
||
from odoo import SUPERUSER_ID, api | ||
from odoo.tools.sql import table_exists | ||
|
||
|
||
def migrate(cr, version): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
# Migrate stock_request's analytic account and tags | ||
if table_exists(cr, "account_analytic_distribution"): # 16.0 | ||
fill_analytic_distribution( | ||
env, | ||
"stock_request", | ||
"account_analytic_tag_stock_request_rel", | ||
"stock_request_id", | ||
) | ||
else: # 17.0, analytic account only | ||
cr.execute( | ||
""" | ||
update stock_request set analytic_distribution = | ||
json_build_object(analytic_account_id::varchar, 100.0) | ||
where analytic_account_id is not null; | ||
""" | ||
) | ||
# Migrate stock_request_order's analytic account | ||
cr.execute( | ||
""" | ||
update stock_request_order set analytic_distribution = | ||
json_build_object(default_analytic_account_id::varchar, 100.0) | ||
where default_analytic_account_id is not null; | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
from . import analytic | ||
from . import stock_rule | ||
from . import stock_request | ||
from . import stock_request_order |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,9 @@ | ||
# Copyright 2018 Creu Blanca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
MAP_ACTIONS = { | ||
"analytic_account": "analytic.action_account_analytic_account_form", | ||
"analytic_tag": "analytic.account_analytic_tag_action", | ||
} | ||
MAP_FIELDS = { | ||
"analytic_account": "analytic_account_ids", | ||
"analytic_tag": "analytic_tag_ids", | ||
} | ||
MAP_VIEWS = { | ||
"analytic_account": "analytic.view_account_analytic_account_form", | ||
"analytic_tag": "analytic.account_analytic_tag_form_view", | ||
} | ||
from odoo import models | ||
|
||
|
||
class StockRequestOrder(models.Model): | ||
_inherit = "stock.request.order" | ||
|
||
analytic_count = fields.Integer( | ||
compute="_compute_analytic_ids", | ||
readonly=True, | ||
compute_sudo=True, | ||
) | ||
analytic_tag_count = fields.Integer( | ||
compute="_compute_analytic_ids", | ||
readonly=True, | ||
compute_sudo=True, | ||
) | ||
analytic_account_ids = fields.One2many( | ||
comodel_name="account.analytic.account", | ||
compute="_compute_analytic_ids", | ||
string="Analytic Accounts", | ||
readonly=True, | ||
compute_sudo=True, | ||
) | ||
analytic_tag_ids = fields.One2many( | ||
comodel_name="account.analytic.tag", | ||
compute="_compute_analytic_ids", | ||
string="Analytic Tags", | ||
readonly=True, | ||
compute_sudo=True, | ||
) | ||
default_analytic_account_id = fields.Many2one( | ||
comodel_name="account.analytic.account", | ||
string="Default Analytic Account", | ||
help="Set this if you want to define a default analytic account on requests", | ||
) | ||
|
||
@api.depends("stock_request_ids") | ||
def _compute_analytic_ids(self): | ||
for req in self: | ||
req.analytic_account_ids = req.stock_request_ids.mapped( | ||
"analytic_account_id" | ||
) | ||
req.analytic_tag_ids = req.stock_request_ids.mapped("analytic_tag_ids") | ||
req.analytic_count = len(req.analytic_account_ids) | ||
req.analytic_tag_count = len(req.analytic_tag_ids) | ||
|
||
def action_view_analytic(self): | ||
self.ensure_one() | ||
analytic_type = self.env.context.get("analytic_type") | ||
if not analytic_type: | ||
raise ValidationError( | ||
_("Analytic type (analytic_type) not present in the context") | ||
) | ||
xmlid = MAP_ACTIONS[analytic_type] | ||
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) | ||
records = self.mapped(MAP_FIELDS[analytic_type]) | ||
if len(records) > 1: | ||
action["domain"] = [("id", "in", records.ids)] | ||
elif records: | ||
action["views"] = [ | ||
(self.env.ref(MAP_VIEWS[self._context["analytic_type"]]).id, "form") | ||
] | ||
action["res_id"] = records.id | ||
return action | ||
_name = "stock.request.order" | ||
_inherit = ["analytic.mixin", "stock.request.order"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Assign the analytic account to the stock request. | ||
To create stock moves with a specific analytic distribution, assign an analytic | ||
distribution to each stock request or set an analytic distribution on the stock | ||
request order as a default value for new stock requests on that order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.