Skip to content

Commit

Permalink
adaugare testscript
Browse files Browse the repository at this point in the history
  • Loading branch information
dhongu committed Jan 3, 2024
1 parent 347964c commit 932e2ee
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deltatech_stock_valuation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Product Valuation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33959730018c9387a7ec885775c0defca536f43dedde3733f43288f3066e2ffc
!! source digest: sha256:8eab2c74d7882455da233440e00230d9cb2b775f7dad006976ef0347213375a0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down
2 changes: 1 addition & 1 deletion deltatech_stock_valuation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"category": "Inventory/Inventory",
"depends": ["stock_account"],
"depends": ["stock_account", "l10n_ro"],
"license": "OPL-1",
"data": [
"security/ir.model.access.csv",
Expand Down
5 changes: 3 additions & 2 deletions deltatech_stock_valuation/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class ResCompany(models.Model):
valuation_area_id = fields.Many2one("valuation.area", string="Valuation Area")

def set_stock_valuation_at_company_level(self):
self.ensure_one()
if self.valuation_area_level != "company":
return

if not self.valuation_area_id:
valuation_area = self.env["valuation.area"].create(
{
"name": self.company_id.name,
"company_id": self.company_id.id,
"name": self.name,
"company_id": self.id,
}
)
self.valuation_area_id = valuation_area.id
Expand Down
2 changes: 1 addition & 1 deletion deltatech_stock_valuation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Product Valuation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33959730018c9387a7ec885775c0defca536f43dedde3733f43288f3066e2ffc
!! source digest: sha256:8eab2c74d7882455da233440e00230d9cb2b775f7dad006976ef0347213375a0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="https://www.odoo.com/documentation/master/legal/licenses.html"><img alt="License: OPL-1" src="https://img.shields.io/badge/licence-OPL--1-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/dhongu/deltatech/tree/15.0/deltatech_stock_valuation"><img alt="dhongu/deltatech" src="https://img.shields.io/badge/github-dhongu%2Fdeltatech-lightgray.png?logo=github" /></a></p>
<p>Features:</p>
Expand Down
5 changes: 5 additions & 0 deletions deltatech_stock_valuation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2024 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons rcoot folder for license details

from . import test_stock_valuation
119 changes: 119 additions & 0 deletions deltatech_stock_valuation/tests/test_stock_valuation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# © 2024 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons rcoot folder for license details

from dateutil.relativedelta import relativedelta

from odoo import Command, fields
from odoo.tests import tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestStockValuation(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
if not chart_template_ref:
chart_template_ref = "l10n_ro.ro_chart_template"
super().setUpClass(chart_template_ref=chart_template_ref)

cls.company = cls.env.company

cls.account = cls.env["account.account"].create(
{
"name": "Account A",
"code": "1234",
"user_type_id": cls.env.ref("account.data_account_type_current_assets").id,
"stock_valuation": True,
}
)

cls.sale_journal = cls.env["account.journal"].create(
{
"name": "Test Journal",
"type": "sale",
"code": "TEST",
}
)

cls.env.company.set_stock_valuation_at_company_level()

def test_account_move(self):
today = fields.Date.today()
today = fields.Date.from_string(today)
date = today + relativedelta(day=1, months=-1, days=15)

invoices = self.env["account.move"].create(
[
{
"move_type": "out_invoice",
"invoice_date": date,
"date": date,
"partner_id": self.partner_a.id,
"invoice_line_ids": [
Command.create(
{
"product_id": self.product_a.id,
"account_id": self.account.id,
"quantity": 5.0,
"price_unit": 1000.0,
"tax_ids": [Command.set(self.company_data["default_tax_sale"].ids)],
}
)
],
},
{
"move_type": "out_invoice",
"invoice_date": date,
"date": date,
"partner_id": self.company_data["company"].partner_id.id,
"invoice_line_ids": [
Command.create(
{
"product_id": self.product_a.id,
"account_id": self.account.id,
"quantity": 2.0,
"price_unit": 1500.0,
"tax_ids": [Command.set(self.company_data["default_tax_sale"].ids)],
}
)
],
},
{
"move_type": "out_refund",
"invoice_date": date,
"date": date,
"partner_id": self.partner_a.id,
"invoice_line_ids": [
Command.create(
{
"product_id": self.product_a.id,
"account_id": self.account.id,
"quantity": 3.0,
"price_unit": 1000.0,
"tax_ids": [Command.set(self.company_data["default_tax_sale"].ids)],
}
)
],
},
{
"move_type": "in_invoice",
"invoice_date": date,
"date": date,
"partner_id": self.partner_b.id,
"invoice_line_ids": [
Command.create(
{
"product_id": self.product_b.id,
"account_id": self.account.id,
"quantity": 10.0,
"price_unit": 800.0,
"tax_ids": [Command.set(self.company_data["default_tax_purchase"].ids)],
}
)
],
},
]
)
invoices.action_post()

0 comments on commit 932e2ee

Please sign in to comment.