Skip to content

Commit

Permalink
[MIG] purchase_stock_analytic: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomacr committed Jan 20, 2023
1 parent 0ae0949 commit ffab8b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion purchase_stock_analytic/__manifest__.py
Expand Up @@ -5,7 +5,7 @@
"name": "Purchase Stock Analytic",
"summary": """
Copies the analytic account of the purchase order item to the stock move""",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
Expand Down
9 changes: 3 additions & 6 deletions purchase_stock_analytic/models/purchase_order_line.py
Expand Up @@ -11,10 +11,7 @@ class PurchaseOrderLine(models.Model):
def _prepare_stock_moves(self, picking):
res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
for line in res:
account_analytic = self.account_analytic_id
analytic_tags = self.analytic_tag_ids
if account_analytic:
line.update({"analytic_account_id": account_analytic.id})
if analytic_tags:
line.update({"analytic_tag_ids": [(6, 0, analytic_tags.ids)]})
analytic_distribution = self.analytic_distribution
if analytic_distribution:
line.update({"analytic_distribution": analytic_distribution})
return res
18 changes: 5 additions & 13 deletions purchase_stock_analytic/tests/test_purchase_stock_analytic.py
Expand Up @@ -12,15 +12,14 @@ def setUpClass(cls):
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.purchase_order_model = cls.env["purchase.order"]
cls.purchase_order_line_model = cls.env["purchase.order.line"]
cls.analytic_tag_model = cls.env["account.analytic.tag"]
cls.product_model = cls.env["product.product"]
cls.res_partner_model = cls.env["res.partner"]

cls.analytic_tag_1 = cls.analytic_tag_model.create({"name": "Tag test 1"})
cls.analytic_tag_2 = cls.analytic_tag_model.create({"name": "Tag test 2"})
cls.partner = cls.res_partner_model.create({"name": "Partner test"})
cls.product = cls.product_model.create({"name": "Product test"})
cls.analytic_account = cls.env.ref("analytic.analytic_agrolait")
cls.analytic_distribution = dict(
{str(cls.env.ref("analytic.analytic_agrolait").id): 100.0}
)

cls.purchase_order = cls.purchase_order_model.create(
{"partner_id": cls.partner.id}
Expand All @@ -32,10 +31,7 @@ def setUpClass(cls):
"order_id": cls.purchase_order.id,
"price_unit": 20,
"product_id": cls.product.id,
"account_analytic_id": cls.analytic_account.id,
"analytic_tag_ids": [
(6, 0, [cls.analytic_tag_1.id, cls.analytic_tag_2.id])
],
"analytic_distribution": cls.analytic_distribution,
"date_planned": fields.Datetime.today(),
"product_uom": cls.product.uom_po_id.id,
}
Expand All @@ -44,8 +40,4 @@ def setUpClass(cls):
def test_purchase_stock_analytic(self):
self.purchase_order.button_confirm()
self.move = self.purchase_order.picking_ids.move_ids_without_package
self.assertEqual(self.move.analytic_account_id, self.analytic_account)
self.assertEqual(
self.move.analytic_tag_ids.ids,
[self.analytic_tag_1.id, self.analytic_tag_2.id],
)
self.assertEqual(self.move.analytic_distribution, self.analytic_distribution)

0 comments on commit ffab8b2

Please sign in to comment.