| 1 |
from odoo import api, models, Command |
| 2 |
|
| 3 |
class PosConfig(models.Model): |
| 4 |
_inherit = 'pos.config' |
| 5 |
|
| 6 |
def _create_takeaway_fiscal_position(self, config): |
| 7 |
ChartTemplate = self.env['account.chart.template'].with_company(self.env.company) |
| 8 |
tax_21 = ChartTemplate.ref('attn_VAT-OUT-21-L', raise_if_not_found=False) |
| 9 |
tax_12 = ChartTemplate.ref('attn_VAT-OUT-12-L', raise_if_not_found=False) |
| 10 |
tax_6 = ChartTemplate.ref('attn_VAT-OUT-06-L', raise_if_not_found=False) |
| 11 |
|
| 12 |
if tax_21 and tax_12 and tax_6: |
| 13 |
fp = self.env['account.fiscal.position'].create({ |
| 14 |
'name': 'Take out', |
| 15 |
}) |
| 16 |
tax_6.copy({ |
| 17 |
'name': f"{tax_6.name} Take out", |
| 18 |
'fiscal_position_ids': [Command.set(fp.ids)], |
| 19 |
'original_tax_ids': [Command.set((tax_12 | tax_21).ids)], |
| 20 |
}) |
| 21 |
takeaway_preset = self.env.ref('pos_restaurant.pos_takeout_preset', raise_if_not_found=False) |
| 22 |
if takeaway_preset: |
| 23 |
takeaway_preset.write({'fiscal_position_id': fp.id}) |
| 24 |
|
| 25 |
def _load_bar_demo_data(self, with_demo_data=True): |
| 26 |
super()._load_bar_demo_data(with_demo_data) |
| 27 |
if (self.env.company.chart_template or '').startswith('be'): |
| 28 |
ChartTemplate = self.env['account.chart.template'].with_company(self.env.company) |
| 29 |
tax_alcohol = ChartTemplate.ref('tax_alcohol_luxury') |
| 30 |
cocktails_category = self.env.ref('pos_restaurant.pos_category_cocktails', raise_if_not_found=False) |
| 31 |
if cocktails_category: |
| 32 |
self.env['product.template'].search([ |
| 33 |
('pos_categ_ids', 'in', [cocktails_category.id]) |
| 34 |
]).write({'taxes_id': [(6, 0, [tax_alcohol.id])]}) |
| 35 |
|
| 36 |
@api.model |
| 37 |
def load_onboarding_restaurant_scenario(self, with_demo_data=True): |
| 38 |
res = super().load_onboarding_restaurant_scenario(with_demo_data) |
| 39 |
if (self.env.company.chart_template or '').startswith('be'): |
| 40 |
config = self.env.ref(self._get_suffixed_ref_name('pos_restaurant.pos_config_main_restaurant'), raise_if_not_found=False) |
| 41 |
if config: |
| 42 |
self._create_takeaway_fiscal_position(config) |
| 43 |
return res |