[IMP] point_of_sale: Adapt tests to work with/without demo data
This commit is contained in:
@@ -15,7 +15,7 @@ class AccountBankStatement(models.Model):
|
||||
for bs in self:
|
||||
if bs.pos_session_id.state in ('opened', 'closing_control') and bs.state == 'open':
|
||||
raise UserError(_("You can't validate a bank statement that is used in an opened Session of a Point of Sale."))
|
||||
return super( AccountBankStatement, self).check_confirm_bank()
|
||||
return super(AccountBankStatement, self).check_confirm_bank()
|
||||
|
||||
|
||||
class AccountBankStatementLine(models.Model):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
@@ -524,7 +524,7 @@ class PosConfig(models.Model):
|
||||
'target': 'self',
|
||||
}
|
||||
|
||||
def open_session_cb(self):
|
||||
def open_session_cb(self, check_coa=True):
|
||||
""" new session button
|
||||
|
||||
create one if none exist
|
||||
@@ -532,7 +532,7 @@ class PosConfig(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
if not self.current_session_id:
|
||||
if not self.company_has_template:
|
||||
if check_coa and not tools.config['test_enable'] and not self.company_has_template:
|
||||
raise UserError(_("A Chart of Accounts is not yet installed in your current company. Please install a "
|
||||
"Chart of Accounts through the Invoicing/Accounting settings before launching a PoS session." ))
|
||||
self._check_company_journal()
|
||||
|
||||
@@ -1,59 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from random import randint
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests.common import TransactionCase, Form
|
||||
from odoo import fields, tools
|
||||
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
|
||||
from odoo.tests.common import SavepointCase, Form
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
|
||||
class TestPointOfSaleCommon(TransactionCase):
|
||||
class TestPointOfSaleCommon(StockAccountMinimalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPointOfSaleCommon, self).setUp()
|
||||
self.AccountBankStatement = self.env['account.bank.statement']
|
||||
self.AccountBankStatementLine = self.env['account.bank.statement.line']
|
||||
self.PosMakePayment = self.env['pos.make.payment']
|
||||
self.PosOrder = self.env['pos.order']
|
||||
self.PosSession = self.env['pos.session']
|
||||
self.company = self.env.ref('base.main_company')
|
||||
self.company_id = self.company.id
|
||||
coa = self.env['account.chart.template'].search([
|
||||
('currency_id', '=', self.company.currency_id.id),
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestPointOfSaleCommon, cls).setUpClass()
|
||||
|
||||
cls.AccountBankStatement = cls.env['account.bank.statement']
|
||||
cls.AccountBankStatementLine = cls.env['account.bank.statement.line']
|
||||
cls.PosMakePayment = cls.env['pos.make.payment']
|
||||
cls.PosOrder = cls.env['pos.order']
|
||||
cls.PosSession = cls.env['pos.session']
|
||||
cls.company = cls.env.ref('base.main_company')
|
||||
cls.company_id = cls.company.id
|
||||
coa = cls.env['account.chart.template'].search([
|
||||
('currency_id', '=', cls.company.currency_id.id),
|
||||
], limit=1)
|
||||
test_sale_journal = self.env['account.journal'].create({'name': 'Sales Journal - Test',
|
||||
'code': 'TSJ',
|
||||
'type': 'sale',
|
||||
'company_id': self.company_id})
|
||||
self.company.write({'anglo_saxon_accounting': coa.use_anglo_saxon,
|
||||
test_sale_journal = cls.env['account.journal'].create({
|
||||
'name': 'Sales Journal - Test',
|
||||
'code': 'TSJ',
|
||||
'type': 'sale',
|
||||
'company_id': cls.company_id})
|
||||
cls.company.write({
|
||||
'anglo_saxon_accounting': coa.use_anglo_saxon,
|
||||
'bank_account_code_prefix': coa.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': coa.cash_account_code_prefix,
|
||||
'transfer_account_code_prefix': coa.transfer_account_code_prefix,
|
||||
'chart_template_id': coa.id,
|
||||
'chart_template_id': coa.id,})
|
||||
cls.product3 = cls.env['product.product'].create({
|
||||
'name': 'Product 3',
|
||||
'list_price': 450,
|
||||
})
|
||||
self.product3 = self.env.ref('product.product_product_3')
|
||||
self.product4 = self.env.ref('product.product_product_4')
|
||||
self.partner1 = self.env.ref('base.res_partner_1')
|
||||
self.partner4 = self.env.ref('base.res_partner_4')
|
||||
self.pos_config = self.env.ref('point_of_sale.pos_config_main')
|
||||
self.pos_config.write({
|
||||
cls.product4 = cls.env['product.product'].create({
|
||||
'name': 'Product 4',
|
||||
'list_price': 750,
|
||||
})
|
||||
cls.partner1 = cls.env['res.partner'].create({'name': 'Partner 1'})
|
||||
cls.partner4 = cls.env['res.partner'].create({'name': 'Partner 4'})
|
||||
cls.pos_config = cls.env.ref('point_of_sale.pos_config_main')
|
||||
cls.pos_config.write({
|
||||
'journal_id': test_sale_journal.id,
|
||||
'invoice_journal_id': test_sale_journal.id,
|
||||
})
|
||||
self.led_lamp = self.env.ref('point_of_sale.led_lamp')
|
||||
self.whiteboard_pen = self.env.ref('point_of_sale.whiteboard_pen')
|
||||
self.newspaper_rack = self.env.ref('point_of_sale.newspaper_rack')
|
||||
|
||||
self.cash_payment_method = self.pos_config.payment_method_ids.filtered(lambda pm: pm.name == 'Cash')
|
||||
self.bank_payment_method = self.pos_config.payment_method_ids.filtered(lambda pm: pm.name == 'Bank')
|
||||
self.credit_payment_method = self.env['pos.payment.method'].create({
|
||||
'name': 'Credit',
|
||||
'receivable_account_id': self.company.account_default_pos_receivable_account_id.id,
|
||||
'split_transactions': True,
|
||||
cls.led_lamp = cls.env['product.product'].create({
|
||||
'name': 'LED Lamp',
|
||||
'available_in_pos': True,
|
||||
'list_price': 0.90,
|
||||
})
|
||||
cls.whiteboard_pen = cls.env['product.product'].create({
|
||||
'name': 'Whiteboard Pen',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.20,
|
||||
})
|
||||
cls.newspaper_rack = cls.env['product.product'].create({
|
||||
'name': 'Newspaper Rack',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.28,
|
||||
})
|
||||
cls.default_receivable_account = cls.a_recv
|
||||
cls.company.account_default_pos_receivable_account_id = cls.default_receivable_account
|
||||
cls.cash_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Cash',
|
||||
'receivable_account_id': cls.default_receivable_account.id,
|
||||
'is_cash_count': True,
|
||||
'cash_journal_id': cls.cash_journal.id,
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
})
|
||||
cls.bank_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Bank',
|
||||
'receivable_account_id': cls.default_receivable_account.id,
|
||||
'is_cash_count': False,
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
})
|
||||
cls.credit_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Credit',
|
||||
'receivable_account_id': cls.default_receivable_account.id,
|
||||
'split_transactions': True,
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
})
|
||||
cls.pos_config.write({'payment_method_ids': [(4, cls.credit_payment_method.id), (4, cls.bank_payment_method.id), (4, cls.cash_payment_method.id)]})
|
||||
|
||||
# Create POS journal
|
||||
cls.pos_config.journal_id = cls.env['account.journal'].create({
|
||||
'type': 'sale',
|
||||
'name': 'Point of Sale',
|
||||
'code': 'POSS - Test',
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
'sequence': 20
|
||||
})
|
||||
self.pos_config.write({'payment_method_ids': [(4, self.credit_payment_method.id)]})
|
||||
|
||||
# create a VAT tax of 10%, included in the public price
|
||||
Tax = self.env['account.tax']
|
||||
Tax = cls.env['account.tax']
|
||||
account_tax_10_incl = Tax.create({
|
||||
'name': 'VAT 10 perc Incl',
|
||||
'amount_type': 'percent',
|
||||
@@ -63,7 +107,7 @@ class TestPointOfSaleCommon(TransactionCase):
|
||||
|
||||
# assign this 10 percent tax on the [PCSC234] PC Assemble SC234 product
|
||||
# as a sale tax
|
||||
self.product3.taxes_id = [(6, 0, [account_tax_10_incl.id])]
|
||||
cls.product3.taxes_id = [(6, 0, [account_tax_10_incl.id])]
|
||||
|
||||
# create a VAT tax of 5%, which is added to the public price
|
||||
account_tax_05_incl = Tax.create({
|
||||
@@ -76,27 +120,32 @@ class TestPointOfSaleCommon(TransactionCase):
|
||||
# create a second VAT tax of 5% but this time for a child company, to
|
||||
# ensure that only product taxes of the current session's company are considered
|
||||
#(this tax should be ignore when computing order's taxes in following tests)
|
||||
account_tax_05_incl_chicago = Tax.with_context(default_company_id=self.ref('stock.res_company_1')).create({
|
||||
another_company = cls.env['res.company'].create({
|
||||
'name': 'My Other Company',
|
||||
'partner_id': cls.env['res.partner'].create({'name': 'My Other Company Partner'}).id,
|
||||
})
|
||||
|
||||
account_tax_05_incl_chicago = Tax.with_context(default_company_id=another_company.id).create({
|
||||
'name': 'VAT 05 perc Excl (US)',
|
||||
'amount_type': 'percent',
|
||||
'amount': 5.0,
|
||||
'price_include': 0,
|
||||
})
|
||||
|
||||
self.product4.company_id = False
|
||||
cls.product4.company_id = False
|
||||
# I assign those 5 percent taxes on the PCSC349 product as a sale taxes
|
||||
self.product4.write(
|
||||
cls.product4.write(
|
||||
{'taxes_id': [(6, 0, [account_tax_05_incl.id, account_tax_05_incl_chicago.id])]})
|
||||
|
||||
# Set account_id in the generated repartition lines. Automatically, nothing is set.
|
||||
invoice_rep_lines = (account_tax_05_incl | account_tax_05_incl_chicago | account_tax_10_incl).mapped('invoice_repartition_line_ids')
|
||||
refund_rep_lines = (account_tax_05_incl | account_tax_05_incl_chicago | account_tax_10_incl).mapped('refund_repartition_line_ids')
|
||||
|
||||
tax_received_account = self.company.account_sale_tax_id.mapped('invoice_repartition_line_ids.account_id')
|
||||
(invoice_rep_lines | refund_rep_lines).write({'account_id': tax_received_account.id})
|
||||
# Expense account, should just be something else than receivable/payable
|
||||
(invoice_rep_lines | refund_rep_lines).write({'account_id': cls.a_expense.id})
|
||||
|
||||
|
||||
class TestPoSCommon(TransactionCase):
|
||||
class TestPoSCommon(StockAccountMinimalTest):
|
||||
""" Set common values for different special test cases.
|
||||
|
||||
The idea is to set up common values here for the tests
|
||||
@@ -104,56 +153,63 @@ class TestPoSCommon(TransactionCase):
|
||||
this class.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestPoSCommon, self).setUp()
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestPoSCommon, cls).setUpClass()
|
||||
|
||||
self.pos_manager = self.env.ref('base.user_admin')
|
||||
self.env = self.env(user=self.pos_manager)
|
||||
cls.pos_manager = cls.env.ref('base.user_admin')
|
||||
cls.env = cls.env(user=cls.pos_manager)
|
||||
|
||||
# Set basic defaults
|
||||
self.company = self.env.ref('base.main_company')
|
||||
self.pos_sale_journal = self.env['account.journal'].create({
|
||||
cls.company = cls.env.ref('base.main_company')
|
||||
cls.pos_sale_journal = cls.env['account.journal'].create({
|
||||
'type': 'sale',
|
||||
'name': 'Point of Sale Test',
|
||||
'code': 'POST',
|
||||
'company_id': self.company.id,
|
||||
'company_id': cls.company.id,
|
||||
'sequence': 20
|
||||
})
|
||||
self.invoice_journal = self.env['account.journal'].create({
|
||||
cls.invoice_journal = cls.env['account.journal'].create({
|
||||
'type': 'sale',
|
||||
'name': 'Invoice Journal Test',
|
||||
'code': 'INVT',
|
||||
'company_id': self.company.id,
|
||||
'company_id': cls.company.id,
|
||||
'sequence': 21
|
||||
})
|
||||
self.receivable_account = self.pos_manager.partner_id.property_account_receivable_id
|
||||
self.tax_received_account = self.company.account_sale_tax_id.mapped('invoice_repartition_line_ids.account_id')
|
||||
self.pos_receivable_account = self.company.account_default_pos_receivable_account_id
|
||||
self.other_receivable_account = self.env['account.account'].create({
|
||||
cls.receivable_account = cls.pos_manager.partner_id.property_account_receivable_id
|
||||
cls.tax_received_account = cls.a_expense # Whatever the account, just not receivable/payable
|
||||
cls.company.account_default_pos_receivable_account_id = cls.env['account.account'].create({
|
||||
'code': 'X1012 - POS',
|
||||
'name': 'Debtors - (POS)',
|
||||
'reconcile': True,
|
||||
'user_type_id': cls.env.ref('account.data_account_type_receivable').id,
|
||||
})
|
||||
cls.pos_receivable_account = cls.company.account_default_pos_receivable_account_id
|
||||
cls.other_receivable_account = cls.env['account.account'].create({
|
||||
'name': 'Other Receivable',
|
||||
'code': 'RCV00' ,
|
||||
'user_type_id': self.env['account.account.type'].create({'name': 'RCV type', 'type': 'receivable', 'internal_group': 'asset'}).id,
|
||||
'user_type_id': cls.env['account.account.type'].create({'name': 'RCV type', 'type': 'receivable', 'internal_group': 'asset'}).id,
|
||||
'internal_group': 'asset',
|
||||
'reconcile': True,
|
||||
})
|
||||
|
||||
# company_currency can be different from `base.USD` depending on the localization installed
|
||||
self.company_currency = self.company.currency_id
|
||||
cls.company_currency = cls.company.currency_id
|
||||
# other_currency is a currency different from the company_currency
|
||||
# sometimes company_currency is different from USD, so handle appropriately.
|
||||
self.other_currency = self.env.ref('base.EUR') if self.company_currency == self.env.ref('base.USD') else self.env.ref('base.USD')
|
||||
cls.other_currency = cls.env.ref('base.EUR') if cls.company_currency == cls.env.ref('base.USD') else cls.env.ref('base.USD')
|
||||
|
||||
self.currency_pricelist = self.env['product.pricelist'].create({
|
||||
cls.currency_pricelist = cls.env['product.pricelist'].create({
|
||||
'name': 'Public Pricelist',
|
||||
'currency_id': self.company_currency.id,
|
||||
'currency_id': cls.company_currency.id,
|
||||
})
|
||||
# Set Point of Sale configurations
|
||||
# basic_config
|
||||
# - derived from 'point_of_sale.pos_config_main' with added invoice_journal_id and credit payment method.
|
||||
# other_currency_config
|
||||
# - pos.config set to have currency different from company currency.
|
||||
self.basic_config = self._create_basic_config()
|
||||
self.other_currency_config = self._create_other_currency_config()
|
||||
cls.basic_config = cls._create_basic_config()
|
||||
cls.other_currency_config = cls._create_other_currency_config()
|
||||
|
||||
# Set product categories
|
||||
# categ_basic
|
||||
@@ -161,97 +217,117 @@ class TestPoSCommon(TransactionCase):
|
||||
# categ_anglo
|
||||
# - product category with fifo and real_time valuations
|
||||
# - used for checking anglo saxon accounting behavior
|
||||
self.categ_basic = self.env.ref('product.product_category_all')
|
||||
self.categ_anglo = self._create_categ_anglo()
|
||||
cls.categ_basic = cls.env.ref('product.product_category_all')
|
||||
cls.env.company.anglo_saxon_accounting = True
|
||||
cls.categ_anglo = cls._create_categ_anglo()
|
||||
|
||||
# other basics
|
||||
self.sale_account = self.categ_basic.property_account_income_categ_id
|
||||
self.other_sale_account = self.env['account.account'].search([
|
||||
('company_id', '=', self.company.id),
|
||||
('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id),
|
||||
('id', '!=', self.sale_account.id)
|
||||
cls.sale_account = cls.categ_basic.property_account_income_categ_id
|
||||
cls.other_sale_account = cls.env['account.account'].search([
|
||||
('company_id', '=', cls.company.id),
|
||||
('user_type_id', '=', cls.env.ref('account.data_account_type_revenue').id),
|
||||
('id', '!=', cls.sale_account.id)
|
||||
], limit=1)
|
||||
|
||||
# Set customers
|
||||
self.customer = self.env['res.partner'].create({'name': 'Test Customer'})
|
||||
self.other_customer = self.env['res.partner'].create({'name': 'Other Customer', 'property_account_receivable_id': self.other_receivable_account.id})
|
||||
cls.customer = cls.env['res.partner'].create({'name': 'Test Customer'})
|
||||
cls.other_customer = cls.env['res.partner'].create({'name': 'Other Customer', 'property_account_receivable_id': cls.other_receivable_account.id})
|
||||
|
||||
# Set taxes
|
||||
# self.taxes => dict
|
||||
# cls.taxes => dict
|
||||
# keys: 'tax7', 'tax10'(price_include=True), 'tax_group_7_10'
|
||||
self.taxes = self._create_taxes()
|
||||
cls.taxes = cls._create_taxes()
|
||||
|
||||
cls.stock_location_components = cls.env["stock.location"].create({
|
||||
'name': 'Shelf 1',
|
||||
'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id,
|
||||
})
|
||||
|
||||
#####################
|
||||
## private methods ##
|
||||
#####################
|
||||
|
||||
def _create_basic_config(self):
|
||||
new_config = Form(self.env['pos.config'])
|
||||
@classmethod
|
||||
def _create_basic_config(cls):
|
||||
new_config = Form(cls.env['pos.config'])
|
||||
new_config.name = 'PoS Shop Test'
|
||||
new_config.module_account = True
|
||||
new_config.invoice_journal_id = self.invoice_journal
|
||||
new_config.journal_id = self.pos_sale_journal
|
||||
new_config.invoice_journal_id = cls.invoice_journal
|
||||
new_config.journal_id = cls.pos_sale_journal
|
||||
new_config.available_pricelist_ids.clear()
|
||||
new_config.available_pricelist_ids.add(self.currency_pricelist)
|
||||
new_config.pricelist_id = self.currency_pricelist
|
||||
new_config.available_pricelist_ids.add(cls.currency_pricelist)
|
||||
new_config.pricelist_id = cls.currency_pricelist
|
||||
config = new_config.save()
|
||||
cash_journal = config.payment_method_ids.filtered(lambda pm: pm.is_cash_count)[:1].cash_journal_id
|
||||
cash_split_pm = self.env['pos.payment.method'].create({
|
||||
cash_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Cash',
|
||||
'receivable_account_id': cls.pos_receivable_account.id,
|
||||
'is_cash_count': True,
|
||||
'cash_journal_id': cls.cash_journal.id,
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
})
|
||||
bank_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Bank',
|
||||
'receivable_account_id': cls.pos_receivable_account.id,
|
||||
'is_cash_count': False,
|
||||
'company_id': cls.env.user.company_id.id,
|
||||
})
|
||||
cash_split_pm = cls.env['pos.payment.method'].create({
|
||||
'name': 'Split (Cash) PM',
|
||||
'receivable_account_id': self.pos_receivable_account.id,
|
||||
'receivable_account_id': cls.pos_receivable_account.id,
|
||||
'split_transactions': True,
|
||||
'is_cash_count': True,
|
||||
'cash_journal_id': cash_journal.id,
|
||||
'cash_journal_id': cls.cash_journal.id,
|
||||
})
|
||||
config.write({'payment_method_ids': [(4,cash_split_pm.id,0)]})
|
||||
config.write({'payment_method_ids': [(4, cash_split_pm.id), (4, cash_payment_method.id), (4, bank_payment_method.id)]})
|
||||
return config
|
||||
|
||||
def _create_other_currency_config(self):
|
||||
(self.other_currency.rate_ids | self.company_currency.rate_ids).unlink()
|
||||
self.env['res.currency.rate'].create({
|
||||
@classmethod
|
||||
def _create_other_currency_config(cls):
|
||||
(cls.other_currency.rate_ids | cls.company_currency.rate_ids).unlink()
|
||||
cls.env['res.currency.rate'].create({
|
||||
'rate': 0.5,
|
||||
'currency_id': self.other_currency.id,
|
||||
'currency_id': cls.other_currency.id,
|
||||
})
|
||||
other_cash_journal = self.env['account.journal'].create({
|
||||
other_cash_journal = cls.env['account.journal'].create({
|
||||
'name': 'Cash Other',
|
||||
'type': 'cash',
|
||||
'company_id': self.company.id,
|
||||
'company_id': cls.company.id,
|
||||
'code': 'CSHO',
|
||||
'sequence': 10,
|
||||
'currency_id': self.other_currency.id
|
||||
'currency_id': cls.other_currency.id
|
||||
})
|
||||
other_invoice_journal = self.env['account.journal'].create({
|
||||
other_invoice_journal = cls.env['account.journal'].create({
|
||||
'name': 'Customer Invoice Other',
|
||||
'type': 'sale',
|
||||
'company_id': self.company.id,
|
||||
'company_id': cls.company.id,
|
||||
'code': 'INVO',
|
||||
'sequence': 11,
|
||||
'currency_id': self.other_currency.id
|
||||
'currency_id': cls.other_currency.id
|
||||
})
|
||||
other_sales_journal = self.env['account.journal'].create({
|
||||
other_sales_journal = cls.env['account.journal'].create({
|
||||
'name':'PoS Sale Other',
|
||||
'type': 'sale',
|
||||
'code': 'POSO',
|
||||
'company_id': self.company.id,
|
||||
'company_id': cls.company.id,
|
||||
'sequence': 12,
|
||||
'currency_id': self.other_currency.id
|
||||
'currency_id': cls.other_currency.id
|
||||
})
|
||||
other_pricelist = self.env['product.pricelist'].create({
|
||||
other_pricelist = cls.env['product.pricelist'].create({
|
||||
'name': 'Public Pricelist Other',
|
||||
'currency_id': self.other_currency.id,
|
||||
'currency_id': cls.other_currency.id,
|
||||
})
|
||||
other_cash_payment_method = self.env['pos.payment.method'].create({
|
||||
other_cash_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Cash Other',
|
||||
'receivable_account_id': self.pos_receivable_account.id,
|
||||
'receivable_account_id': cls.pos_receivable_account.id,
|
||||
'is_cash_count': True,
|
||||
'cash_journal_id': other_cash_journal.id,
|
||||
})
|
||||
other_bank_payment_method = self.env['pos.payment.method'].create({
|
||||
other_bank_payment_method = cls.env['pos.payment.method'].create({
|
||||
'name': 'Bank Other',
|
||||
'receivable_account_id': self.pos_receivable_account.id,
|
||||
'receivable_account_id': cls.pos_receivable_account.id,
|
||||
})
|
||||
|
||||
new_config = Form(self.env['pos.config'])
|
||||
new_config = Form(cls.env['pos.config'])
|
||||
new_config.name = 'Shop Other'
|
||||
new_config.invoice_journal_id = other_invoice_journal
|
||||
new_config.journal_id = other_sales_journal
|
||||
@@ -265,24 +341,29 @@ class TestPoSCommon(TransactionCase):
|
||||
config = new_config.save()
|
||||
return config
|
||||
|
||||
def _create_categ_anglo(self):
|
||||
return self.env['product.category'].create({
|
||||
@classmethod
|
||||
def _create_categ_anglo(cls):
|
||||
cls.o_income.reconcile = True
|
||||
return cls.env['product.category'].create({
|
||||
'name': 'Anglo',
|
||||
'parent_id': False,
|
||||
'property_cost_method': 'fifo',
|
||||
'property_valuation': 'real_time',
|
||||
'property_stock_account_input_categ_id': cls.o_expense.id,
|
||||
'property_stock_account_output_categ_id': cls.o_income.id,
|
||||
})
|
||||
|
||||
def _create_taxes(self):
|
||||
@classmethod
|
||||
def _create_taxes(cls):
|
||||
""" Create taxes
|
||||
|
||||
tax7: 7%, excluded in product price
|
||||
tax10: 10%, included in product price
|
||||
"""
|
||||
tax7 = self.env['account.tax'].create({'name': 'Tax 7%', 'amount': 7})
|
||||
tax10 = self.env['account.tax'].create({'name': 'Tax 10%', 'amount': 10, 'price_include': True, 'include_base_amount': False})
|
||||
(tax7 | tax10).mapped('invoice_repartition_line_ids').write({'account_id': self.tax_received_account.id})
|
||||
(tax7 | tax10).mapped('refund_repartition_line_ids').write({'account_id': self.tax_received_account.id})
|
||||
tax7 = cls.env['account.tax'].create({'name': 'Tax 7%', 'amount': 7})
|
||||
tax10 = cls.env['account.tax'].create({'name': 'Tax 10%', 'amount': 10, 'price_include': True, 'include_base_amount': False})
|
||||
(tax7 | tax10).mapped('invoice_repartition_line_ids').write({'account_id': cls.tax_received_account.id})
|
||||
(tax7 | tax10).mapped('refund_repartition_line_ids').write({'account_id': cls.tax_received_account.id})
|
||||
|
||||
tax_group_7_10 = tax7.copy()
|
||||
with Form(tax_group_7_10) as tax:
|
||||
@@ -394,8 +475,9 @@ class TestPoSCommon(TransactionCase):
|
||||
'to_invoice': is_invoiced,
|
||||
}
|
||||
|
||||
def create_product(self, name, category, lst_price, standard_price=None, tax_ids=None, sale_account=None):
|
||||
product = self.env['product.product'].create({
|
||||
@classmethod
|
||||
def create_product(cls, name, category, lst_price, standard_price=None, tax_ids=None, sale_account=None):
|
||||
product = cls.env['product.product'].create({
|
||||
'type': 'product',
|
||||
'available_in_pos': True,
|
||||
'taxes_id': [(5, 0, 0)] if not tax_ids else [(6, 0, tax_ids)],
|
||||
@@ -409,19 +491,20 @@ class TestPoSCommon(TransactionCase):
|
||||
product.property_account_income_id = sale_account
|
||||
return product
|
||||
|
||||
def adjust_inventory(self, products, quantities):
|
||||
@classmethod
|
||||
def adjust_inventory(cls, products, quantities):
|
||||
""" Adjust inventory of the given products
|
||||
"""
|
||||
inventory = self.env['stock.inventory'].create({
|
||||
inventory = cls.env['stock.inventory'].create({
|
||||
'name': 'Inventory adjustment'
|
||||
})
|
||||
for product, qty in zip(products, quantities):
|
||||
self.env['stock.inventory.line'].create({
|
||||
cls.env['stock.inventory.line'].create({
|
||||
'product_id': product.id,
|
||||
'product_uom_id': self.env.ref('uom.product_uom_unit').id,
|
||||
'product_uom_id': cls.env.ref('uom.product_uom_unit').id,
|
||||
'inventory_id': inventory.id,
|
||||
'product_qty': qty,
|
||||
'location_id': self.env.ref('stock.stock_location_components').id,
|
||||
'location_id': cls.stock_location_components.id,
|
||||
})
|
||||
inventory._action_start()
|
||||
inventory.action_validate()
|
||||
@@ -445,7 +528,7 @@ class TestPoSCommon(TransactionCase):
|
||||
* bank_pm : bank payment method of the session
|
||||
* cash_split_pm : credit payment method of the session
|
||||
"""
|
||||
self.config.open_session_cb()
|
||||
self.config.open_session_cb(check_coa=False)
|
||||
self.pos_session = self.config.current_session_id
|
||||
self.currency = self.pos_session.currency_id
|
||||
self.pricelist = self.pos_session.config_id.pricelist_id
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo
|
||||
import time
|
||||
@@ -14,9 +15,8 @@ class TestAngloSaxonCommon(common.TransactionCase):
|
||||
self.Statement = self.env['account.bank.statement']
|
||||
self.company = self.env.ref('base.main_company')
|
||||
self.warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
|
||||
self.product = self.env.ref('product.product_product_3')
|
||||
self.partner = self.env.ref('base.res_partner_1')
|
||||
self.category = self.env.ref('product.product_category_1')
|
||||
self.partner = self.env['res.partner'].create({'name': 'Partner 1'})
|
||||
self.category = self.env.ref('product.product_category_all')
|
||||
self.category = self.category.copy({'name': 'New category','property_valuation': 'real_time'})
|
||||
account_type_rcv = self.env.ref('account.data_account_type_receivable')
|
||||
account_type_inc = self.env.ref('account.data_account_type_revenue')
|
||||
@@ -35,7 +35,12 @@ class TestAngloSaxonCommon(common.TransactionCase):
|
||||
self.category.property_stock_journal = self.env['account.journal'].create({'name': 'Stock journal', 'type': 'sale', 'code': 'STK00'})
|
||||
self.pos_config = self.env.ref('point_of_sale.pos_config_main')
|
||||
self.pos_config = self.pos_config.copy({'name': 'New POS config'})
|
||||
self.product = self.product.copy({'name': 'New product','standard_price': 100})
|
||||
self.product = self.env['product.product'].create({
|
||||
'name': 'New product',
|
||||
'standard_price': 100,
|
||||
'available_in_pos': True,
|
||||
'type': 'product',
|
||||
})
|
||||
self.company.anglo_saxon_accounting = True
|
||||
self.product.categ_id = self.category
|
||||
self.product.property_account_expense_id = account_expense
|
||||
@@ -61,7 +66,7 @@ class TestAngloSaxonFlow(TestAngloSaxonCommon):
|
||||
def test_create_account_move_line(self):
|
||||
# This test will check that the correct journal entries are created when a product in real time valuation
|
||||
# is sold in a company using anglo-saxon
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
current_session = self.pos_config.current_session_id
|
||||
self.cash_journal.loss_account_id = self.account
|
||||
|
||||
@@ -142,7 +147,7 @@ class TestAngloSaxonFlow(TestAngloSaxonCommon):
|
||||
self.assertEqual(self.product.quantity_svl, 10)
|
||||
|
||||
self.pos_config.module_account = True
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
|
||||
pos_order_values = {
|
||||
'company_id': self.company.id,
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
from odoo.api import Environment
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from datetime import date, timedelta
|
||||
|
||||
import odoo.tests
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
class TestUi(odoo.tests.HttpCase):
|
||||
def test_01_pos_basic_order(self):
|
||||
|
||||
class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
env = self.env(user=self.env.ref('base.user_admin'))
|
||||
|
||||
journal_obj = env['account.journal']
|
||||
account_obj = env['account.account']
|
||||
main_company = env.ref('base.main_company')
|
||||
main_pos_config = env.ref('point_of_sale.pos_config_main')
|
||||
self.main_pos_config = env.ref('point_of_sale.pos_config_main')
|
||||
|
||||
env['res.partner'].create({
|
||||
'name': 'Deco Addict',
|
||||
})
|
||||
|
||||
account_receivable = account_obj.create({'code': 'X1012',
|
||||
'name': 'Account Receivable - Test',
|
||||
'user_type_id': env.ref('account.data_account_type_receivable').id,
|
||||
'reconcile': True})
|
||||
self.env.company.account_default_pos_receivable_account_id = account_receivable
|
||||
field = env['ir.model.fields']._get('res.partner', 'property_account_receivable_id')
|
||||
env['ir.property'].create({'name': 'property_account_receivable_id',
|
||||
'company_id': main_company.id,
|
||||
@@ -35,8 +43,64 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'sequence': 10,
|
||||
})
|
||||
|
||||
# Archive all existing product to avoid noise during the tours
|
||||
all_pos_product = self.env['product.product'].search([('available_in_pos', '=', True)])
|
||||
discount = self.env.ref('point_of_sale.product_product_consumable')
|
||||
tip = self.env.ref('point_of_sale.product_product_tip')
|
||||
(all_pos_product - discount - tip)._write({'active': False})
|
||||
|
||||
# test an extra price on an attribute
|
||||
pear = env.ref('point_of_sale.whiteboard')
|
||||
pear = env['product.product'].create({
|
||||
'name': 'Whiteboard Pen',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.20,
|
||||
'taxes_id': False,
|
||||
'weight': 0.01,
|
||||
'to_weight': True,
|
||||
})
|
||||
wall_shelf = env['product.product'].create({
|
||||
'name': 'Wall Shelf Unit',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.98,
|
||||
'taxes_id': False,
|
||||
})
|
||||
small_shelf = env['product.product'].create({
|
||||
'name': 'Small Shelf',
|
||||
'available_in_pos': True,
|
||||
'list_price': 2.83,
|
||||
'taxes_id': False,
|
||||
})
|
||||
magnetic_board = env['product.product'].create({
|
||||
'name': 'Magnetic Board',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.98,
|
||||
'taxes_id': False,
|
||||
})
|
||||
monitor_stand = env['product.product'].create({
|
||||
'name': 'Monitor Stand',
|
||||
'available_in_pos': True,
|
||||
'list_price': 3.19,
|
||||
'taxes_id': False,
|
||||
})
|
||||
desk_pad = env['product.product'].create({
|
||||
'name': 'Desk Pad',
|
||||
'available_in_pos': True,
|
||||
'list_price': 1.98,
|
||||
'taxes_id': False,
|
||||
})
|
||||
letter_tray = env['product.product'].create({
|
||||
'name': 'Letter Tray',
|
||||
'available_in_pos': True,
|
||||
'list_price': 4.80,
|
||||
'taxes_id': False,
|
||||
})
|
||||
desk_organizer = env['product.product'].create({
|
||||
'name': 'Desk Organizer',
|
||||
'available_in_pos': True,
|
||||
'list_price': 5.10,
|
||||
'taxes_id': False,
|
||||
})
|
||||
|
||||
attribute = env['product.attribute'].create({
|
||||
'name': 'add 2',
|
||||
})
|
||||
@@ -60,12 +124,12 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 2,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.wall_shelf').id,
|
||||
'product_id': wall_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 13.95, # test for issues like in 7f260ab517ebde634fc274e928eb062463f0d88f
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.small_shelf').id,
|
||||
'product_id': small_shelf.id,
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -75,17 +139,17 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 100,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.wall_shelf').id,
|
||||
'product_id': wall_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 99,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.small_shelf').id,
|
||||
'product_id': small_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 0,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.magnetic_board').id,
|
||||
'product_id': magnetic_board.id,
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -96,33 +160,33 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'price_discount': 6,
|
||||
'price_surcharge': 5,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.wall_shelf').id,
|
||||
'product_id': wall_shelf.id,
|
||||
}), (0, 0, {
|
||||
# .99 prices
|
||||
'compute_price': 'formula',
|
||||
'price_surcharge': -0.01,
|
||||
'price_round': 1,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.small_shelf').id,
|
||||
'product_id': small_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'formula',
|
||||
'price_min_margin': 10,
|
||||
'price_max_margin': 100,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.magnetic_board').id,
|
||||
'product_id': magnetic_board.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'formula',
|
||||
'price_surcharge': 10,
|
||||
'price_max_margin': 5,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.monitor_stand').id,
|
||||
'product_id': monitor_stand.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'formula',
|
||||
'price_discount': -100,
|
||||
'price_min_margin': 5,
|
||||
'price_max_margin': 20,
|
||||
'applied_on': '0_product_variant',
|
||||
'product_id': env.ref('point_of_sale.desk_pad').id,
|
||||
'product_id': desk_pad.id,
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -133,13 +197,13 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'fixed_price': 1,
|
||||
'applied_on': '0_product_variant',
|
||||
'min_quantity': 2,
|
||||
'product_id': env.ref('point_of_sale.wall_shelf').id,
|
||||
'product_id': wall_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 2,
|
||||
'applied_on': '0_product_variant',
|
||||
'min_quantity': 1,
|
||||
'product_id': env.ref('point_of_sale.wall_shelf').id,
|
||||
'product_id': wall_shelf.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 2,
|
||||
@@ -155,13 +219,18 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 1,
|
||||
'applied_on': '1_product',
|
||||
'product_tmpl_id': env.ref('point_of_sale.wall_shelf_product_template').id,
|
||||
'product_tmpl_id': wall_shelf.product_tmpl_id.id,
|
||||
}), (0, 0, {
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 2,
|
||||
})],
|
||||
})
|
||||
|
||||
product_category_3 = env['product.category'].create({
|
||||
'name': 'Services',
|
||||
'parent_id': env.ref('product.product_category_1').id,
|
||||
})
|
||||
|
||||
env['product.pricelist'].create({
|
||||
# no category has precedence over category
|
||||
'name': 'Category vs no category',
|
||||
@@ -169,7 +238,7 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 1,
|
||||
'applied_on': '2_product_category',
|
||||
'categ_id': env.ref('product.product_category_3').id, # All / Saleable / Services
|
||||
'categ_id': product_category_3.id, # All / Saleable / Services
|
||||
}), (0, 0, {
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 2,
|
||||
@@ -187,7 +256,7 @@ class TestUi(odoo.tests.HttpCase):
|
||||
'compute_price': 'fixed',
|
||||
'fixed_price': 1,
|
||||
'applied_on': '2_product_category',
|
||||
'categ_id': env.ref('product.product_category_3').id, # All / Saleable / Services
|
||||
'categ_id': product_category_3.id, # All / Saleable / Services
|
||||
})],
|
||||
})
|
||||
|
||||
@@ -263,7 +332,11 @@ class TestUi(odoo.tests.HttpCase):
|
||||
excluded_pricelist = env['product.pricelist'].create({
|
||||
'name': 'Not loaded'
|
||||
})
|
||||
env.ref('base.res_partner_18').property_product_pricelist = excluded_pricelist
|
||||
res_partner_18 = self.env['res.partner'].create({
|
||||
'name': 'Lumber Inc',
|
||||
'is_company': True,
|
||||
})
|
||||
res_partner_18.property_product_pricelist = excluded_pricelist
|
||||
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'TEST PARTNER',
|
||||
@@ -287,10 +360,9 @@ class TestUi(odoo.tests.HttpCase):
|
||||
src_tax = env['account.tax'].create({'name': "SRC", 'amount': 10})
|
||||
dst_tax = env['account.tax'].create({'name': "DST", 'amount': 5})
|
||||
|
||||
env.ref('point_of_sale.letter_tray').taxes_id = [(6, 0, [src_tax.id])]
|
||||
letter_tray.taxes_id = [(6, 0, [src_tax.id])]
|
||||
|
||||
|
||||
main_pos_config.write({
|
||||
self.main_pos_config.write({
|
||||
'tax_regime_selection': True,
|
||||
'fiscal_position_ids': [(0, 0, {
|
||||
'name': "FP-POS-2M",
|
||||
@@ -321,18 +393,23 @@ class TestUi(odoo.tests.HttpCase):
|
||||
('res_id', '=', False)
|
||||
]).write({'value_reference': 'product.pricelist,%s' % public_pricelist.id})
|
||||
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
class TestUi(TestPointOfSaleHttpCommon):
|
||||
def test_01_pos_basic_order(self):
|
||||
|
||||
# open a session, the /pos/web controller will redirect to it
|
||||
main_pos_config.open_session_cb()
|
||||
self.main_pos_config.open_session_cb(check_coa=False)
|
||||
|
||||
# needed because tests are run before the module is marked as
|
||||
# installed. In js web will only load qweb coming from modules
|
||||
# that are returned by the backend in module_boot. Without
|
||||
# this you end up with js, css but no qweb.
|
||||
env['ir.module.module'].search([('name', '=', 'point_of_sale')], limit=1).state = 'installed'
|
||||
self.env['ir.module.module'].search([('name', '=', 'point_of_sale')], limit=1).state = 'installed'
|
||||
|
||||
self.start_tour("/pos/web?config_id=%d" % main_pos_config.id, 'pos_pricelist', login="admin")
|
||||
self.start_tour("/pos/web?config_id=%d" % self.main_pos_config.id, 'pos_pricelist', login="admin")
|
||||
|
||||
self.start_tour("/pos/web?config_id=%d" % main_pos_config.id, 'pos_basic_order', login="admin")
|
||||
self.start_tour("/pos/web?config_id=%d" % self.main_pos_config.id, 'pos_basic_order', login="admin")
|
||||
|
||||
for order in env['pos.order'].search([]):
|
||||
for order in self.env['pos.order'].search([]):
|
||||
self.assertEqual(order.state, 'paid', "Validated order has payment of " + str(order.amount_paid) + " and total of " + str(order.amount_total))
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import time
|
||||
|
||||
import odoo
|
||||
from odoo import fields
|
||||
from odoo import fields, tools
|
||||
from odoo.tools import float_compare, mute_logger, test_reports
|
||||
from odoo.tests.common import Form
|
||||
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon
|
||||
@@ -13,7 +15,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
|
||||
|
||||
def test_order_refund(self):
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
current_session = self.pos_config.current_session_id
|
||||
# I create a new PoS order with 2 lines
|
||||
order = self.PosOrder.create({
|
||||
@@ -94,7 +96,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
return untax, sum(tax.get('amount', 0.0) for tax in res['taxes'])
|
||||
|
||||
# I click on create a new session button
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
current_session = self.pos_config.current_session_id
|
||||
|
||||
# I create a PoS order with 2 units of PCSC234 at 450 EUR
|
||||
@@ -305,7 +307,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
untax = res['total_excluded']
|
||||
return untax, sum(tax.get('amount', 0.0) for tax in res['taxes'])
|
||||
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
current_session = self.pos_config.current_session_id
|
||||
|
||||
untax1, atax1 = compute_tax(self.product3, 450*0.95, 2)
|
||||
@@ -427,7 +429,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
return untax, sum(tax.get('amount', 0.0) for tax in res['taxes'])
|
||||
|
||||
# I click on create a new session button
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
|
||||
current_session = self.pos_config.current_session_id
|
||||
num_starting_orders = len(current_session.order_ids)
|
||||
@@ -607,7 +609,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
})
|
||||
|
||||
# I click on create a new session button
|
||||
eur_config.open_session_cb()
|
||||
eur_config.open_session_cb(check_coa=False)
|
||||
current_session = eur_config.current_session_id
|
||||
|
||||
# I create a PoS order with 2 units of PCSC234 at 450 EUR (Tax Incl)
|
||||
@@ -706,8 +708,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
self.assertAlmostEqual(a, b)
|
||||
|
||||
def test_order_to_invoice_no_tax(self):
|
||||
|
||||
self.pos_config.open_session_cb()
|
||||
self.pos_config.open_session_cb(check_coa=False)
|
||||
current_session = self.pos_config.current_session_id
|
||||
|
||||
# I create a new PoS order with 2 units of PC1 at 450 EUR (Tax Incl) and 3 units of PCSC349 at 300 EUR. (Tax Excl)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo.tests
|
||||
from odoo.tests import HttpCase, tagged
|
||||
from odoo import tools
|
||||
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
class TestUi(odoo.tests.HttpCase):
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestUi(HttpCase):
|
||||
|
||||
# Avoid "A Chart of Accounts is not yet installed in your current company."
|
||||
# Everything is set up correctly even without installed CoA
|
||||
@tools.mute_logger('odoo.http')
|
||||
def test_01_point_of_sale_tour(self):
|
||||
|
||||
self.start_tour("/web", 'point_of_sale_tour', login="admin")
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo
|
||||
|
||||
from odoo import tools
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
class TestPoSBasicConfig(TestPoSCommon):
|
||||
""" Test PoS with basic configuration
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo
|
||||
|
||||
from odoo import tools
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo
|
||||
|
||||
from odoo import tools
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@odoo.tests.tagged('post_install', '-at_install')
|
||||
@@ -14,6 +19,7 @@ class TestPoSMultipleSaleAccounts(TestPoSCommon):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPoSMultipleSaleAccounts, self).setUp()
|
||||
|
||||
self.config = self.basic_config
|
||||
self.product1 = self.create_product(
|
||||
'Product 1',
|
||||
@@ -81,6 +87,7 @@ class TestPoSMultipleSaleAccounts(TestPoSCommon):
|
||||
| Total balance | 0.00 |
|
||||
+---------------------+---------+
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
@@ -160,6 +167,7 @@ class TestPoSMultipleSaleAccounts(TestPoSCommon):
|
||||
| Total balance | 0.00 |
|
||||
+---------------------+---------+
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo
|
||||
|
||||
from odoo import tools
|
||||
from odoo.tests.common import Form
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@@ -9,6 +14,7 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPoSOtherCurrencyConfig, self).setUp()
|
||||
|
||||
self.config = self.other_currency_config
|
||||
self.product1 = self.create_product('Product 1', self.categ_basic, 10.0, 5)
|
||||
self.product2 = self.create_product('Product 2', self.categ_basic, 20.0, 10)
|
||||
@@ -25,6 +31,7 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon):
|
||||
# Product price should be half of the original price because currency rate is 0.5.
|
||||
# (see `self._create_other_currency_config` method)
|
||||
# Except for product2 where the price is specified in the pricelist.
|
||||
|
||||
self.assertAlmostEqual(self.config.pricelist_id.get_product_price(self.product1, 1, self.customer), 5.00)
|
||||
self.assertAlmostEqual(self.config.pricelist_id.get_product_price(self.product2, 1, self.customer), 12.99)
|
||||
self.assertAlmostEqual(self.config.pricelist_id.get_product_price(self.product3, 1, self.customer), 15.00)
|
||||
@@ -60,6 +67,7 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon):
|
||||
| Total balance | 0.0 | 0.00 |
|
||||
+---------------------+---------+-----------------+
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
@@ -124,6 +132,7 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon):
|
||||
| Total balance | 0.0 | 0.00 |
|
||||
+---------------------+---------+-----------------+
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
|
||||
import odoo
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@@ -8,6 +13,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPoSProductsWithTax, self).setUp()
|
||||
|
||||
self.config = self.basic_config
|
||||
self.product1 = self.create_product(
|
||||
'Product 1',
|
||||
@@ -60,6 +66,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
|
||||
|
||||
Thus, manually_calculated_taxes = (-24,89, -51.82)
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
@@ -134,6 +141,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
|
||||
|
||||
Thus, manually_calculated_taxes = (-6.81, -44.54)
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
@@ -182,7 +190,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
|
||||
# check receivable line
|
||||
# should be equivalent to receivable in the invoice
|
||||
# should also be fully-reconciled
|
||||
receivable_line = session_move.line_ids.filtered(lambda line: line.account_id == self.receivable_account)
|
||||
receivable_line = session_move.line_ids.filtered(lambda line: line.account_id in self.receivable_account + self.env['account.account'].search([('name', '=', 'Account Receivable (PoS)')]) and line.name == 'From invoiced orders')
|
||||
self.assertAlmostEqual(receivable_line.balance, -426.09)
|
||||
self.assertTrue(receivable_line.full_reconcile_id, msg='Receivable line for invoices should be fully reconciled.')
|
||||
|
||||
@@ -229,6 +237,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
|
||||
|
||||
manually_calculated_taxes = (4.01, 6.37)
|
||||
"""
|
||||
|
||||
self.open_new_session()
|
||||
|
||||
# create orders
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
import odoo
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@@ -10,6 +14,7 @@ class TestPoSSetup(TestPoSCommon):
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestPoSSetup, self).setUp()
|
||||
|
||||
self.config = self.basic_config
|
||||
self.products = [
|
||||
self.create_product('Product 1', self.categ_basic, lst_price=10.0, standard_price=5),
|
||||
@@ -18,6 +23,7 @@ class TestPoSSetup(TestPoSCommon):
|
||||
]
|
||||
|
||||
def test_basic_config_values(self):
|
||||
|
||||
config = self.basic_config
|
||||
self.assertEqual(config.currency_id, self.company_currency)
|
||||
self.assertEqual(config.pricelist_id.currency_id, self.company_currency)
|
||||
@@ -41,6 +47,7 @@ class TestPoSSetup(TestPoSCommon):
|
||||
def get_price(pricelist, product):
|
||||
return pricelist.get_product_price(product, 1, self.customer)
|
||||
|
||||
|
||||
# check usd pricelist
|
||||
pricelist = self.basic_config.pricelist_id
|
||||
for product in self.products:
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
import odoo
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@@ -7,6 +11,7 @@ class TestPoSStock(TestPoSCommon):
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestPoSStock, self).setUp()
|
||||
|
||||
self.config = self.basic_config
|
||||
self.product1 = self.create_product('Product 1', self.categ_anglo, 10.0, 5.0)
|
||||
self.product2 = self.create_product('Product 2', self.categ_anglo, 20.0, 10.0)
|
||||
@@ -98,7 +103,7 @@ class TestPoSStock(TestPoSCommon):
|
||||
sales_line = account_move.line_ids.filtered(lambda line: line.account_id == self.sale_account)
|
||||
self.assertAlmostEqual(sales_line.balance, -orders_total, msg='Sales line balance should be equal to total orders amount.')
|
||||
|
||||
receivable_line_cash = account_move.line_ids.filtered(lambda line: self.pos_receivable_account == line.account_id and self.cash_pm.name in line.name)
|
||||
receivable_line_cash = account_move.line_ids.filtered(lambda line: line.account_id in self.pos_receivable_account + self.env['account.account'].search([('name', '=', 'Account Receivable (PoS)')]) and self.cash_pm.name in line.name)
|
||||
self.assertAlmostEqual(receivable_line_cash.balance, 1010.0, msg='Cash receivable should be equal to the total cash payments.')
|
||||
|
||||
expense_line = account_move.line_ids.filtered(lambda line: line.account_id == self.expense_account)
|
||||
@@ -176,7 +181,7 @@ class TestPoSStock(TestPoSCommon):
|
||||
receivable_line = account_move.line_ids.filtered(lambda line: line.account_id == self.receivable_account)
|
||||
self.assertAlmostEqual(receivable_line.balance, -360.0, msg='Receivable line balance should equal the negative of total amount of invoiced orders.')
|
||||
|
||||
receivable_line_cash = account_move.line_ids.filtered(lambda line: self.pos_receivable_account == line.account_id and self.cash_pm.name in line.name)
|
||||
receivable_line_cash = account_move.line_ids.filtered(lambda line: line.account_id in self.pos_receivable_account + self.env['account.account'].search([('name', '=', 'Account Receivable (PoS)')]) and self.cash_pm.name in line.name)
|
||||
self.assertAlmostEqual(receivable_line_cash.balance, 1010.0, msg='Cash receivable should be equal to the total cash payments.')
|
||||
|
||||
expense_line = account_move.line_ids.filtered(lambda line: line.account_id == self.expense_account)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
import odoo
|
||||
from odoo.addons.point_of_sale.tests.common import TestPoSCommon
|
||||
|
||||
@@ -8,51 +12,54 @@ class TestPoSWithFiscalPosition(TestPoSCommon):
|
||||
keywords/phrases: fiscal position
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestPoSWithFiscalPosition, self).setUp()
|
||||
self.config = self.basic_config
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestPoSWithFiscalPosition, cls).setUpClass()
|
||||
|
||||
self.new_tax_17 = self.env['account.tax'].create({'name': 'New Tax 17%', 'amount': 17})
|
||||
self.new_tax_17.invoice_repartition_line_ids.write({'account_id': self.tax_received_account.id})
|
||||
cls.config = cls.basic_config
|
||||
|
||||
self.fpos = self._create_fiscal_position()
|
||||
self.fpos_no_tax_dest = self._create_fiscal_position_no_tax_dest()
|
||||
cls.new_tax_17 = cls.env['account.tax'].create({'name': 'New Tax 17%', 'amount': 17})
|
||||
cls.new_tax_17.invoice_repartition_line_ids.write({'account_id': cls.tax_received_account.id})
|
||||
|
||||
self.product1 = self.create_product(
|
||||
cls.fpos = cls._create_fiscal_position()
|
||||
cls.fpos_no_tax_dest = cls._create_fiscal_position_no_tax_dest()
|
||||
|
||||
cls.product1 = cls.create_product(
|
||||
'Product 1',
|
||||
self.categ_basic,
|
||||
cls.categ_basic,
|
||||
lst_price=10.99,
|
||||
standard_price=5.0,
|
||||
tax_ids=self.taxes['tax7'].ids,
|
||||
tax_ids=cls.taxes['tax7'].ids,
|
||||
)
|
||||
self.product2 = self.create_product(
|
||||
cls.product2 = cls.create_product(
|
||||
'Product 2',
|
||||
self.categ_basic,
|
||||
cls.categ_basic,
|
||||
lst_price=19.99,
|
||||
standard_price=10.0,
|
||||
tax_ids=self.taxes['tax10'].ids,
|
||||
tax_ids=cls.taxes['tax10'].ids,
|
||||
)
|
||||
self.product3 = self.create_product(
|
||||
cls.product3 = cls.create_product(
|
||||
'Product 3',
|
||||
self.categ_basic,
|
||||
cls.categ_basic,
|
||||
lst_price=30.99,
|
||||
standard_price=15.0,
|
||||
tax_ids=self.taxes['tax7'].ids,
|
||||
tax_ids=cls.taxes['tax7'].ids,
|
||||
)
|
||||
self.adjust_inventory([self.product1, self.product2, self.product3], [100, 50, 50])
|
||||
cls.adjust_inventory([cls.product1, cls.product2, cls.product3], [100, 50, 50])
|
||||
|
||||
def _create_fiscal_position(self):
|
||||
fpos = self.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
|
||||
@classmethod
|
||||
def _create_fiscal_position(cls):
|
||||
fpos = cls.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
|
||||
|
||||
account_fpos = self.env['account.fiscal.position.account'].create({
|
||||
account_fpos = cls.env['account.fiscal.position.account'].create({
|
||||
'position_id': fpos.id,
|
||||
'account_src_id': self.sale_account.id,
|
||||
'account_dest_id': self.other_sale_account.id,
|
||||
'account_src_id': cls.sale_account.id,
|
||||
'account_dest_id': cls.other_sale_account.id,
|
||||
})
|
||||
tax_fpos = self.env['account.fiscal.position.tax'].create({
|
||||
tax_fpos = cls.env['account.fiscal.position.tax'].create({
|
||||
'position_id': fpos.id,
|
||||
'tax_src_id': self.taxes['tax7'].id,
|
||||
'tax_dest_id': self.new_tax_17.id,
|
||||
'tax_src_id': cls.taxes['tax7'].id,
|
||||
'tax_dest_id': cls.new_tax_17.id,
|
||||
})
|
||||
fpos.write({
|
||||
'account_ids': [(6, 0, account_fpos.ids)],
|
||||
@@ -60,16 +67,17 @@ class TestPoSWithFiscalPosition(TestPoSCommon):
|
||||
})
|
||||
return fpos
|
||||
|
||||
def _create_fiscal_position_no_tax_dest(self):
|
||||
fpos_no_tax_dest = self.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
|
||||
account_fpos = self.env['account.fiscal.position.account'].create({
|
||||
@classmethod
|
||||
def _create_fiscal_position_no_tax_dest(cls):
|
||||
fpos_no_tax_dest = cls.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
|
||||
account_fpos = cls.env['account.fiscal.position.account'].create({
|
||||
'position_id': fpos_no_tax_dest.id,
|
||||
'account_src_id': self.sale_account.id,
|
||||
'account_dest_id': self.other_sale_account.id,
|
||||
'account_src_id': cls.sale_account.id,
|
||||
'account_dest_id': cls.other_sale_account.id,
|
||||
})
|
||||
tax_fpos = self.env['account.fiscal.position.tax'].create({
|
||||
tax_fpos = cls.env['account.fiscal.position.tax'].create({
|
||||
'position_id': fpos_no_tax_dest.id,
|
||||
'tax_src_id': self.taxes['tax7'].id,
|
||||
'tax_src_id': cls.taxes['tax7'].id,
|
||||
})
|
||||
fpos_no_tax_dest.write({
|
||||
'account_ids': [(6, 0, account_fpos.ids)],
|
||||
@@ -114,6 +122,7 @@ class TestPoSWithFiscalPosition(TestPoSCommon):
|
||||
| Total balance | 0.0 |
|
||||
+---------------------+---------+
|
||||
"""
|
||||
|
||||
self.customer.write({'property_account_position_id': self.fpos.id})
|
||||
self.open_new_session()
|
||||
|
||||
@@ -207,6 +216,7 @@ class TestPoSWithFiscalPosition(TestPoSCommon):
|
||||
| Total balance | 0.0 |
|
||||
+---------------------+---------+
|
||||
"""
|
||||
|
||||
self.customer.write({'property_account_position_id': self.fpos_no_tax_dest.id})
|
||||
self.open_new_session()
|
||||
# create orders
|
||||
@@ -300,6 +310,7 @@ class TestPoSWithFiscalPosition(TestPoSCommon):
|
||||
| Total balance | 0.0 |
|
||||
+---------------------+---------+
|
||||
"""
|
||||
|
||||
self.customer.write({'property_account_position_id': self.fpos.id})
|
||||
self.open_new_session()
|
||||
# create orders
|
||||
|
||||
Reference in New Issue
Block a user