[IMP] point_of_sale: correcly set default values on pos config
When a pos config is created, default values set on it are not allways correct, for the sale journal we are referencing a data, which mean rthat it only worls in the first company. For the invoice journal, we are referencing the wrong journal in the onchannge, etc TASK-ID: 2008468
This commit is contained in:
committed by
Pierre Masereel
parent
56331c1a75
commit
a6b598e645
@@ -76,14 +76,15 @@ class PosConfig(models.Model):
|
||||
return self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1).pos_type_id.id
|
||||
|
||||
def _default_sale_journal(self):
|
||||
journal = self.env.ref('point_of_sale.pos_sale_journal', raise_if_not_found=False)
|
||||
if journal and journal.sudo().company_id == self.env.company:
|
||||
return journal
|
||||
return self._default_invoice_journal()
|
||||
return self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.env.company.id), ('code', '=', 'POSS')], limit=1)
|
||||
|
||||
def _default_invoice_journal(self):
|
||||
return self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.env.company.id)], limit=1)
|
||||
|
||||
def _get_default_journal_ids(self):
|
||||
journals = self.env['account.journal'].search([('journal_user', '=', True), ('type', 'in', ['cash','bank']), ('company_id', '=', self.env.company.id)])
|
||||
return journals or False
|
||||
|
||||
def _default_pricelist(self):
|
||||
return self.env['product.pricelist'].search([('currency_id', '=', self.env.company.currency_id.id)], limit=1)
|
||||
|
||||
@@ -102,7 +103,8 @@ class PosConfig(models.Model):
|
||||
journal_ids = fields.Many2many(
|
||||
'account.journal', 'pos_config_journal_rel',
|
||||
'pos_config_id', 'journal_id', string='Available Payment Methods',
|
||||
domain="[('journal_user', '=', True ), ('type', 'in', ['bank', 'cash'])]",)
|
||||
domain="[('journal_user', '=', True ), ('type', 'in', ['bank', 'cash']), ('company_id', '=', company_id)]",
|
||||
default=lambda self: self._get_default_journal_ids())
|
||||
picking_type_id = fields.Many2one(
|
||||
'stock.picking.type',
|
||||
string='Operation Type',
|
||||
@@ -307,8 +309,8 @@ class PosConfig(models.Model):
|
||||
|
||||
@api.onchange('module_account')
|
||||
def _onchange_module_account(self):
|
||||
if self.module_account:
|
||||
self.invoice_journal_id = self.env.ref('point_of_sale.pos_sale_journal')
|
||||
if self.module_account and not self.invoice_journal_id:
|
||||
self.invoice_journal_id = self._default_invoice_journal()
|
||||
|
||||
@api.onchange('use_pricelist')
|
||||
def _onchange_use_pricelist(self):
|
||||
|
||||
@@ -186,27 +186,6 @@ class PosSession(models.Model):
|
||||
# the .xml files as the CoA is not yet installed.
|
||||
pos_config = self.env['pos.config'].browse(config_id)
|
||||
ctx = dict(self.env.context, company_id=pos_config.company_id.id)
|
||||
if not pos_config.journal_id:
|
||||
default_journals = pos_config.with_context(ctx).default_get(['journal_id', 'invoice_journal_id'])
|
||||
if (not default_journals.get('journal_id') or
|
||||
not default_journals.get('invoice_journal_id')):
|
||||
raise UserError(_("Unable to open the session. You have to assign a sales journal to your point of sale."))
|
||||
pos_config.with_context(ctx).sudo().write({
|
||||
'journal_id': default_journals['journal_id'],
|
||||
'invoice_journal_id': default_journals['invoice_journal_id']})
|
||||
# define some cash journal if no payment method exists
|
||||
if not pos_config.journal_ids:
|
||||
Journal = self.env['account.journal']
|
||||
journals = Journal.with_context(ctx).search([('journal_user', '=', True), ('type', '=', 'cash'), ('company_id', '=', pos_config.company_id.id)])
|
||||
if not journals:
|
||||
journals = Journal.with_context(ctx).search([('type', '=', 'cash'), ('company_id', '=', pos_config.company_id.id)])
|
||||
if not journals:
|
||||
journals = Journal.with_context(ctx).search([('journal_user', '=', True), ('company_id', '=', pos_config.company_id.id)])
|
||||
if not journals:
|
||||
raise ValidationError(_("No payment method configured! \nEither no Chart of Account is installed or no payment method is configured for this POS."))
|
||||
journals.sudo().write({'journal_user': True})
|
||||
pos_config.sudo().write({'journal_ids': [(6, 0, journals.ids)]})
|
||||
|
||||
pos_name = self.env['ir.sequence'].with_context(ctx).next_by_code('pos.session')
|
||||
if values.get('name'):
|
||||
pos_name += ' ' + values['name']
|
||||
|
||||
@@ -11,12 +11,35 @@ class TestPointOfSaleCommon(common.TransactionCase):
|
||||
self.PosMakePayment = self.env['pos.make.payment']
|
||||
self.PosOrder = self.env['pos.order']
|
||||
self.PosSession = self.env['pos.session']
|
||||
self.company_id = self.ref('base.main_company')
|
||||
company = self.env.ref('base.main_company')
|
||||
self.company_id = company.id
|
||||
coa = self.env['account.chart.template'].search([
|
||||
('currency_id', '=', 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})
|
||||
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,
|
||||
})
|
||||
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({
|
||||
'journal_id': test_sale_journal.id,
|
||||
'invoice_journal_id': test_sale_journal.id,
|
||||
'journal_ids': [(0, 0, {'name': 'Cash Journal - Test',
|
||||
'code': 'TSC',
|
||||
'type': 'cash',
|
||||
'company_id': self.company_id,
|
||||
'journal_user': True})],
|
||||
})
|
||||
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')
|
||||
|
||||
@@ -7,7 +7,7 @@ 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):
|
||||
env = self.env(user=self.env.ref('base.user_admin'))
|
||||
|
||||
Reference in New Issue
Block a user