Skip to content

Commit

Permalink
[FIX] refactored for correct use with variants and store revaluation …
Browse files Browse the repository at this point in the history
…in move
  • Loading branch information
serpentcs-dev1 authored and SerpentCS committed Mar 14, 2017
1 parent 21854ac commit d0ae8ce
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 152 deletions.
6 changes: 3 additions & 3 deletions stock_inventory_revaluation/README.rst
Expand Up @@ -12,9 +12,9 @@ inventory revaluation.
You can re-valuate inventory values by:

* Changing the inventory valuation of a specific product. The cost price
is changed, and the inventory value is recalculated according to the new
price. In case of real price, you can select on which quants you want to
change the unit cost.
is changed, and the inventory value is recalculated according to the new
price. In case of real price, you can select on which quants you want to
change the unit cost.

* Changing the value of the inventory. The quantity of inventory remains
unchanged, resulting in a change in the price.
Expand Down
3 changes: 2 additions & 1 deletion stock_inventory_revaluation/__init__.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd.
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizards
4 changes: 3 additions & 1 deletion stock_inventory_revaluation/__openerp__.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd.
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
Expand All @@ -22,6 +23,7 @@
"security/ir.model.access.csv",
"views/stock_inventory_revaluation_view.xml",
"views/product_view.xml",
"views/account_move_line_view.xml",
"data/stock_inventory_revaluation_data.xml",
"wizards/stock_inventory_revaluation_mass_post_view.xml",
],
Expand Down
25 changes: 16 additions & 9 deletions stock_inventory_revaluation/migrations/9.0.1.0.0/post-migration.py
Expand Up @@ -7,22 +7,29 @@
from openerp import api, SUPERUSER_ID
from openupgradelib import openupgrade


def migrate_inventory_revaluation(env):
revaluations = env['stock.inventory.revaluation'].search([])
for revaluation in revaluations:
product_variants = revaluation.product_template_id.product_variant_ids.mapped('id')
product_variants = revaluation.product_template_id.\
with_context(active_test=False).product_variant_ids.mapped('id')
if revaluation.product_template_id and\
revaluation.product_template_id.product_variant_count > 1:
revaluation.product_template_id.product_variant_count > 1:
for product_id in product_variants[1:]:
new_revaluation = revaluation.copy(default={'product_id': product_id,
'state': 'posted',
'account_move_id': revaluation.account_move_id.id})
quants = env['stock.inventory.revaluation.quant'].search([('product_id', '=', product_id),
('revaluation_id', '=', revaluation.id)])
new_revaluation = revaluation.\
copy(default={'product_id': product_id,
'state': 'posted',
'account_move_id': revaluation.
account_move_id.id})
quants = env['stock.inventory.revaluation.quant'].\
search([('product_id', '=', product_id),
('revaluation_id', '=', revaluation.id)])
if quants:
quants.write({'revaluation_id': new_revaluation.id})
prod_dict = {'product_id': product_variants[0]}
revaluation.write(prod_dict)
if product_variants:
prod_dict = {'product_id': product_variants[0]}
revaluation.write(prod_dict)


@openupgrade.migrate()
def migrate(cr, version):
Expand Down
4 changes: 3 additions & 1 deletion stock_inventory_revaluation/models/__init__.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd.
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import product
from . import account_move
from . import stock_inventory_revaluation
46 changes: 46 additions & 0 deletions stock_inventory_revaluation/models/account_move.py
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, exceptions, fields, models, _


class AccountMove(models.Model):

_inherit = 'account.move'

stock_inventory_revaluation_id = fields.Many2one(
comodel_name='stock.inventory.revaluation',
string='Stock Inventory Revaluation',
ondelete='restrict', copy=False)

@api.multi
def unlink(self):
for rec in self:
if rec.stock_inventory_revaluation_id:
raise exceptions.Warning(
_("You cannot remove the journal item that is related "
"to an inventory revaluation"))
return super(AccountMove, self).unlink()


class AccountMoveLine(models.Model):

_inherit = 'account.move.line'

stock_inventory_revaluation_id = fields.Many2one(
comodel_name='stock.inventory.revaluation',
related='move_id.stock_inventory_revaluation_id',
string='Stock Inventory Revaluation',
store=True, ondelete='restrict', copy=False)

@api.multi
def unlink(self):
for rec in self:
if rec.stock_inventory_revaluation_id:
raise exceptions.Warning(
_("You cannot remove the journal item that is related "
"to an inventory revaluation"))
return super(AccountMoveLine, self).unlink()
3 changes: 2 additions & 1 deletion stock_inventory_revaluation/models/product.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# © 2016 Serpent Consulting Services Pvt. Ltd.
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from openerp import api, fields, models
Expand Down

0 comments on commit d0ae8ce

Please sign in to comment.