Browse Source

[ADD] beesdoo_stock_coverage: tests

pull/139/head
robin.keunen 5 years ago
parent
commit
e3acfebf19
  1. 2
      beesdoo_stock_coverage/__manifest__.py
  2. 6
      beesdoo_stock_coverage/models/product_template.py
  3. 104
      beesdoo_stock_coverage/tests/test_stock_coverage.py

2
beesdoo_stock_coverage/__manifest__.py

@ -9,7 +9,7 @@
"author": "Coop IT Easy SCRLfs",
"website": "https://www.coopiteasy.be",
"license": "AGPL-3",
"depends": ["point_of_sale", "sale", "l10n_be"], # fixme
"depends": ["point_of_sale", "sale_stock"],
"data": ["views/product_template_view.xml", "data/cron.xml"],
"installable": True,
"application": False,

6
beesdoo_stock_coverage/models/product_template.py

@ -41,9 +41,9 @@ class ProductTemplate(models.Model):
join product_template template ON product.product_tmpl_id = template.id
where po.state in ('done', 'invoiced', 'paid')
and template.active
and pol.create_date
BETWEEN date_trunc('day', now()) - template.computation_range * interval '1 days'
and date_trunc('day', now())
and po.date_order
BETWEEN now() - template.computation_range * interval '1 days'
and now()
and template.id in %(template_ids)s
group by product_template_id
"""

104
beesdoo_stock_coverage/tests/test_stock_coverage.py

@ -1,22 +1,96 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields
from odoo.tools import float_compare
from odoo.tests.common import TransactionCase
from datetime import timedelta
class TestProductTemplate(TransactionCase):
class TestModule(TransactionCase):
def setUp(self):
super(TestProductTemplate, self).setUp()
self.product1 = self.browse_ref(
"point_of_sale.whiteboard_pen"
).product_tmpl_id
super(TestModule, self).setUp()
# Get Registry
self.PosOrder = self.env["pos.order"]
self.AccountPayment = self.env["account.payment"]
# Get Object
self.pos_product = self.env.ref("product.product_product_25")
self.pos_template = self.pos_product.product_tmpl_id
self.pricelist = self.env.ref("product.list0")
self.partner = self.env.ref("base.res_partner_12")
# Create a new pos config and open it
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
self.pos_config.open_session_cb()
# Test Section
def test_compute_stock_coverage(self):
self.product1._compute_stock_coverage()
print("***")
print(self.product1.range_sales)
print(self.product1.daily_sales)
print(self.product1.stock_coverage)
print("***")
self._create_order()
self.pos_template._compute_stock_coverage()
self.assertEquals(1.0, self.pos_template.range_sales)
self.assertEqual(
float_compare(
0.0714, self.pos_template.daily_sales, precision_digits=2
),
0,
)
self.assertEquals(210.0, self.pos_template.stock_coverage)
def _create_order(self):
date = fields.Date.today() - timedelta(days=1)
date_str = fields.Date.to_string(date)
order_data = {
"id": u"0006-001-0010",
"to_invoice": True,
"data": {
"pricelist_id": self.pricelist.id,
"user_id": 1,
"name": "Order 0006-001-0010",
"partner_id": self.partner.id,
"amount_paid": 0.9,
"pos_session_id": self.pos_config.current_session_id.id,
"lines": [
[
0,
0,
{
"product_id": self.pos_product.id,
"price_unit": 0.9,
"qty": 1,
"price_subtotal": 0.9,
"price_subtotal_incl": 0.9,
},
]
],
"statement_ids": [
[
0,
0,
{
"journal_id": self.pos_config.journal_ids[0].id,
"amount": 0.9,
"name": fields.Datetime.now(),
"account_id": self.env.user.partner_id.property_account_receivable_id.id,
"statement_id": self.pos_config.current_session_id.statement_ids[
0
].id,
},
]
],
"creation_date": date_str,
"amount_tax": 0,
"fiscal_position_id": False,
"uid": u"00001-001-0001",
"amount_return": 0,
"sequence_number": 1,
"amount_total": 0.9,
},
}
result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
return order
Loading…
Cancel
Save