Last active
December 16, 2021 11:23
-
-
Save i-vyshnevska/cc5fa9081634960307cbef70e09390cf to your computer and use it in GitHub Desktop.
Tests
This file contains hidden or 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
cls.env = cls.env(context=dict(cls.env.context,tracking_disable=True,)) | |
####### ALL | |
cls.account = cls.env['account.account'].create({ | |
'code': "1111", | |
'name': "Test", | |
'user_type_id': cls.env.ref('account.data_account_type_receivable').id, | |
'reconcile': True, | |
}) | |
cls.account_sales = cls.account_obj.create({ | |
'code': "X1020", | |
'name': "Product Sales - (test)", | |
'user_type_id': cls.env.ref( | |
'account.data_account_type_revenue').id | |
}) | |
cls.sales_journal = cls.env['account.journal'].create({ | |
'name': "Sales Journal - (test)", | |
'code': "TSAJ", | |
'type': "sale", | |
'refund_sequence': True, | |
'default_debit_account_id': cls.account_sales.id, | |
'default_credit_account_id': cls.account_sales.id, | |
}) | |
###### V12 | |
---------- create product and qty on stock | |
product_model = cls.env['product.product'] | |
product1 = product_model.create( | |
{'name': 'Unittest P1', 'type': 'product'} | |
) | |
cls.stock_loc = cls.env.ref('stock.stock_location_stock') | |
cls.customer_loc = cls.env.ref('stock.stock_location_customers') | |
cls.wh_main = cls.env.ref('stock.warehouse0') | |
cls.env['stock.quant']._update_available_quantity( | |
product1, cls.stock_loc, 10 | |
) | |
------ to try maybe v13 only | |
self.env['stock.quant'].with_context(inventory_mode=True).create({ | |
'product_id': product.id, | |
'location_id': location.id, | |
'inventory_quantity': qty, | |
}) | |
-------------------Confirm picking | |
picking.action_confirm() | |
picking.action_assign() | |
picking.move_lines[0].move_line_ids[0].qty_done = 1.0 | |
picking.move_lines._action_done() | |
---------------------Create payment | |
cls.register_payments_model = cls.env[ | |
'account.register.payments' | |
].with_context(active_model='account.invoice') | |
cls.payment_method_manual_in = cls.env.ref( | |
"account.account_payment_method_manual_in" | |
) | |
cls.bank_journal = cls.env['account.journal'].create( | |
{'name': 'Bank', 'type': 'bank', 'code': 'BNK67'} | |
) | |
ctx = {'active_model': 'account.invoice', 'active_ids': [invoice.id]} | |
register_payments = self.register_payments_model.with_context( | |
ctx | |
).create( | |
{ | |
'payment_date': time.strftime('%Y') + '-07-20', | |
'journal_id': self.bank_journal.id, | |
'payment_method_id': self.payment_method_manual_in.id, | |
'group_invoices': True, | |
} | |
) | |
register_payments.create_payments() | |
--------------------------- Diferent models | |
partner = cls.env["res.partner"].create({"name": "Test"}) | |
stock_location = cls.env.ref("stock.stock_location_stock") | |
cls.additional_product = cls.env["product.product"].create( | |
{"name": "test_product", "type": "product", "tracking": "none"} | |
) | |
product = cls.env.ref('product.product_product_9') | |
cls.env["stock.quant"]._update_available_quantity( | |
cls.additional_product, stock_location, 100 | |
) | |
cls.env["stock.quant"]._update_available_quantity( | |
product, stock_location, 100 | |
) | |
cls.sale_order = cls.env['sale.order'].create( | |
{ | |
'name': 'Test order', | |
'partner_id': partner.id, | |
'order_line': [ | |
( | |
0, | |
0, | |
{ | |
'name': 'Test ', | |
'product_id': product.id, | |
'product_uom_qty': 2, | |
'product_uom': product.uom_id.id, | |
'price_unit': product.list_price, | |
}, | |
) | |
], | |
} | |
) | |
cls.sale_order.action_confirm() | |
# set pickings to done | |
pickings = self.sale_order.picking_ids | |
for line in pickings.mapped("move_lines"): | |
line["quantity_done"] = line["product_uom_qty"] | |
pickings.action_done() | |
-------------------Account test case v10 --------------- | |
# -*- coding: utf-8 -*- | |
# Copyright 2021 Camptocamp SA | |
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) | |
from odoo.exceptions import UserError | |
from odoo.tests import SavepointCase | |
class TestGroupCustomerBilling(SavepointCase): | |
@classmethod | |
def setUpClass(cls): | |
super(TestGroupCustomerBilling, cls).setUpClass() | |
account_user_type = cls.env.ref("account.data_account_type_receivable") | |
cls.invoice_model = cls.env["account.invoice"] | |
partner = cls.env.ref("base.res_partner_2") | |
account_model = cls.env["account.account"] | |
payment_jor = cls.env["account.journal"].search( | |
[("type", "=", "bank")] | |
) | |
cls.env["account.journal"].search([]).write({"update_posted": True}) | |
account = account_model.search( | |
[ | |
( | |
"user_type_id", | |
"=", | |
cls.env.ref("account.data_account_type_revenue").id, | |
) | |
], | |
limit=1, | |
) | |
account_rec_id = account_model.create( | |
dict( | |
code="cust_acc", | |
name="customer account", | |
user_type_id=account_user_type.id, | |
reconcile=True, | |
) | |
) | |
inbound_payment_method = cls.env["account.payment.method"].create( | |
{"name": "inbound", "code": "IN", "payment_type": "inbound"} | |
) | |
invoice_vals = { | |
"partner_id": partner.id, | |
"account_id": account_rec_id.id, | |
"type": "out_invoice", | |
"invoice_line_ids": [ | |
( | |
0, | |
0, | |
{ | |
"name": "Test line", | |
"quantity": 1, | |
"price_unit": 150.0, | |
"account_id": account.id, | |
"product_id": cls.env.ref( | |
"product.product_product_4" | |
).id, | |
}, | |
) | |
], | |
} | |
cls.invoice_zero = cls.invoice_model.create( | |
{ | |
"partner_id": cls.env.ref("base.res_partner_3").id, | |
"account_id": account_rec_id.id, | |
"type": "out_invoice", | |
"invoice_line_ids": [ | |
( | |
0, | |
0, | |
{ | |
"name": "Test line", | |
"quantity": 1, | |
"price_unit": 0.0, | |
"account_id": account.id, | |
"product_id": cls.env.ref( | |
"product.product_product_4" | |
).id, | |
}, | |
) | |
], | |
} | |
) | |
cls.invoice_zero.action_invoice_open() | |
cls.invoice_draft = cls.invoice_model.create(invoice_vals) | |
cls.invoice_open = cls.invoice_model.create(invoice_vals) | |
cls.invoice_open.action_invoice_open() | |
cls.payment = cls.env["account.payment"].create( | |
{ | |
"payment_method_id": inbound_payment_method.id, | |
"payment_type": "inbound", | |
"partner_type": "customer", | |
"partner_id": partner.id, | |
"journal_id": payment_jor.id, | |
"amount": 100, | |
"invoice_ids": [(6, 0, cls.invoice_open.ids)], | |
} | |
) | |
cls.payment.post() | |
def test_cancel_ok(self): | |
self.assertEqual(self.invoice_draft.state, "draft") | |
self.assertEqual(self.invoice_open.state, "open") | |
self.assertEqual(self.invoice_zero.state, "paid") | |
invoices = self.invoice_open + self.invoice_zero | |
with self.assertRaises(UserError): | |
invoices.action_invoice_cancel() | |
invoices -= self.invoice_open | |
invoices.action_invoice_cancel() | |
self.assertEqual(self.invoice_draft.state, "cancel") | |
self.assertEqual(self.invoice_open.state, "open") | |
self.assertEqual(self.invoice_zero.state, "cancel") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment