Skip to content
Snippets Groups Projects
Commit acbca119 authored by Pierre Masereel's avatar Pierre Masereel
Browse files

[IMP] point_of_sale: pos journal for each company

When the accounting localisation is installed after the POS config, the
values on the default POS config which is in data are not completed
because the POS config has been created before any journal exists.

So now, when a chart template is installed, we are completing the POS
config values, and creating the Sale POS journal. We also call the
creation of POS journal when the point_of_sale module is installed after
the template is installed on the database to be sure that we have a
default value for POS journal.

TASK-ID: 2008468
parent a6b598e6
No related branches found
No related tags found
No related merge requests found
......@@ -42,16 +42,9 @@
<field name="image" type="base64" file="point_of_sale/static/img/product_product_49-image.jpg"/>
</record>
<record id="pos_sale_journal" model="account.journal">
<field name="name">Point of Sale</field>
<field name="code">POSS</field>
<field name="type">sale</field>
<!-- avoid being selected as default journal -->
<field name="sequence">20</field>
</record>
<record id="uom.product_uom_categ_unit" model="uom.category">
<field name="is_pos_groupable">True</field>
</record>
<function model="pos.config" name="post_install_pos_localisation" />
</data>
</odoo>
......@@ -5,6 +5,7 @@ from . import account_bank_statement
from . import account_journal
from . import account_tax
from . import barcode_rule
from . import chart_template
from . import digest
from . import pos_category
from . import pos_config
......
# -*- coding: utf-8 -*-
from odoo import api, models
class AccountChartTemplate(models.Model):
_inherit = 'account.chart.template'
def _create_bank_journals(self, company, acc_template_ref):
"""
Add the payment journals to the existing pos config
"""
journals = super(AccountChartTemplate, self)._create_bank_journals(company, acc_template_ref)
self.env['pos.config'].assign_payment_journals(companies=company)
return journals
@api.model
def generate_journals(self, acc_template_ref, company, journals_dict=None):
res = super(AccountChartTemplate, self).generate_journals(acc_template_ref, company, journals_dict)
self.env['pos.config'].generate_pos_journal(companies=company)
return res
......@@ -508,3 +508,41 @@ class PosConfig(models.Model):
'view_id': False,
'type': 'ir.actions.act_window',
}
# All following methods are made to create data needed in POS, when a localisation
# is installed, or if POS is installed on database having companies that already have
# a localisation installed
@api.model
def post_install_pos_localisation(self):
self.assign_payment_journals()
self.generate_pos_journal()
@api.model
def assign_payment_journals(self, companies=False):
self = self.sudo()
if not companies:
companies = self.env['res.company'].search([])
for company in companies:
if company.chart_template_id:
cash_journal = self.env['account.journal'].search([('company_id', '=', company.id), ('type', '=', 'cash')], limit=1)
cash_journal.write({'journal_user':True})
existing_pos_config = self.env['pos.config'].search([('company_id', '=', company.id), ('journal_ids', '=', False)])
existing_pos_config.write({'journal_ids': [(6, 0, cash_journal.ids)]})
@api.model
def generate_pos_journal(self, companies=False):
self = self.sudo()
if not companies:
companies = self.env['res.company'].search([])
for company in companies:
pos_journal = self.env['account.journal'].search([('company_id', '=', company.id), ('code', '=', 'POSS')])
if company.chart_template_id and not pos_journal:
pos_journal = self.env['account.journal'].create({
'type': 'sale',
'name': 'Point of Sale',
'code': 'POSS',
'company_id': company.id,
'sequence': 20
})
existing_pos_config = self.env['pos.config'].search([('company_id', '=', company.id), ('journal_id', '=', False)])
existing_pos_config.write({'journal_id': pos_journal.id})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment