diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/l10n_de/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/l10n_de/models')
| -rw-r--r-- | addons/l10n_de/models/__init__.py | 8 | ||||
| -rw-r--r-- | addons/l10n_de/models/account_move.py | 40 | ||||
| -rw-r--r-- | addons/l10n_de/models/base_document_layout.py | 26 | ||||
| -rw-r--r-- | addons/l10n_de/models/chart_template.py | 23 | ||||
| -rw-r--r-- | addons/l10n_de/models/datev.py | 57 | ||||
| -rw-r--r-- | addons/l10n_de/models/ir_actions_report.py | 10 |
6 files changed, 164 insertions, 0 deletions
diff --git a/addons/l10n_de/models/__init__.py b/addons/l10n_de/models/__init__.py new file mode 100644 index 00000000..f88e3df8 --- /dev/null +++ b/addons/l10n_de/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import datev +from . import base_document_layout +from . import chart_template +from . import ir_actions_report +from . import account_move diff --git a/addons/l10n_de/models/account_move.py b/addons/l10n_de/models/account_move.py new file mode 100644 index 00000000..71ec4a0a --- /dev/null +++ b/addons/l10n_de/models/account_move.py @@ -0,0 +1,40 @@ +from odoo import models, fields, _ +from odoo.tools import format_date + + +class AccountMove(models.Model): + _inherit = 'account.move' + + l10n_de_template_data = fields.Binary(compute='_compute_l10n_de_template_data') + l10n_de_document_title = fields.Char(compute='_compute_l10n_de_document_title') + + def _compute_l10n_de_template_data(self): + for record in self: + record.l10n_de_template_data = data = [] + if record.name: + data.append((_("Invoice No."), record.name)) + if record.invoice_date: + data.append((_("Invoice Date"), format_date(self.env, record.invoice_date))) + if record.invoice_date_due: + data.append((_("Due Date"), format_date(self.env, record.invoice_date_due))) + if record.invoice_origin: + data.append((_("Source"), record.invoice_origin)) + if record.ref: + data.append((_("Reference"), record.ref)) + + def _compute_l10n_de_document_title(self): + for record in self: + record.l10n_de_document_title = '' + if record.move_type == 'out_invoice': + if record.state == 'posted': + record.l10n_de_document_title = _('Invoice') + elif record.state == 'draft': + record.l10n_de_document_title = _('Draft Invoice') + elif record.state == 'cancel': + record.l10n_de_document_title = _('Cancelled Invoice') + elif record.move_type == 'out_refund': + record.l10n_de_document_title = _('Credit Note') + elif record.move_type == 'in_refund': + record.l10n_de_document_title = _('Vendor Credit Note') + elif record.move_type == 'in_invoice': + record.l10n_de_document_title = _('Vendor Bill') diff --git a/addons/l10n_de/models/base_document_layout.py b/addons/l10n_de/models/base_document_layout.py new file mode 100644 index 00000000..6ded58f4 --- /dev/null +++ b/addons/l10n_de/models/base_document_layout.py @@ -0,0 +1,26 @@ +from odoo import models, fields, _ +from odoo.tools import format_date + + +class BaseDocumentLayout(models.TransientModel): + _inherit = 'base.document.layout' + + street = fields.Char(related='company_id.street', readonly=True) + street2 = fields.Char(related='company_id.street2', readonly=True) + zip = fields.Char(related='company_id.zip', readonly=True) + city = fields.Char(related='company_id.city', readonly=True) + company_registry = fields.Char(related='company_id.company_registry', readonly=True) + bank_ids = fields.One2many(related='company_id.partner_id.bank_ids', readonly=True) + l10n_de_template_data = fields.Binary(compute='_compute_l10n_de_template_data') + l10n_de_document_title = fields.Char(compute='_compute_l10n_de_document_title') + + def _compute_l10n_de_template_data(self): + self.l10n_de_template_data = [ + (_("Invoice No."), 'INV/2021/12345'), + (_("Invoice Date"), format_date(self.env, fields.Date.today())), + (_("Due Date"), format_date(self.env, fields.Date.add(fields.Date.today(), days=7))), + (_("Reference"), 'SO/2021/45678'), + ] + + def _compute_l10n_de_document_title(self): + self.l10n_de_document_title = 'Invoice' diff --git a/addons/l10n_de/models/chart_template.py b/addons/l10n_de/models/chart_template.py new file mode 100644 index 00000000..b62a5c2d --- /dev/null +++ b/addons/l10n_de/models/chart_template.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from odoo import api, models + + +class AccountChartTemplate(models.Model): + _inherit = 'account.chart.template' + + @api.model + def _prepare_transfer_account_for_direct_creation(self, name, company): + res = super(AccountChartTemplate, self)._prepare_transfer_account_for_direct_creation(name, company) + if company.country_id.code == 'DE': + xml_id = self.env.ref('l10n_de.tag_de_asset_bs_B_III_2').id + res.setdefault('tag_ids', []) + res['tag_ids'].append((4, xml_id)) + return res + + # Write paperformat and report template used on company + def _load(self, sale_tax_rate, purchase_tax_rate, company): + res = super(AccountChartTemplate, self)._load(sale_tax_rate, purchase_tax_rate, company) + if company.country_id.code == 'DE': + company.write({'external_report_layout_id': self.env.ref('l10n_de.external_layout_din5008').id, + 'paperformat_id': self.env.ref('l10n_de.paperformat_euro_din').id}) + return res diff --git a/addons/l10n_de/models/datev.py b/addons/l10n_de/models/datev.py new file mode 100644 index 00000000..d2e0f8cb --- /dev/null +++ b/addons/l10n_de/models/datev.py @@ -0,0 +1,57 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError +from odoo.tools.translate import _ + +class AccountTaxTemplate(models.Model): + _inherit = 'account.tax.template' + + l10n_de_datev_code = fields.Char(size=2) + + def _get_tax_vals(self, company, tax_template_to_tax): + vals = super(AccountTaxTemplate, self)._get_tax_vals(company, tax_template_to_tax) + vals['l10n_de_datev_code'] = self.l10n_de_datev_code + return vals + +class AccountTax(models.Model): + _inherit = "account.tax" + + l10n_de_datev_code = fields.Char(size=2, help="2 digits code use by Datev") + + +class AccountMove(models.Model): + _inherit = 'account.move' + + def _post(self, soft=True): + # OVERRIDE to check the invoice lines taxes. + for invoice in self.filtered(lambda move: move.is_invoice()): + for line in invoice.invoice_line_ids: + account_tax = line.account_id.tax_ids.ids + if account_tax and invoice.company_id.country_id.code == 'DE': + account_name = line.account_id.name + for tax in line.tax_ids: + if tax.id not in account_tax: + raise UserError(_('Account %s does not authorize to have tax %s specified on the line. \ + Change the tax used in this invoice or remove all taxes from the account') % (account_name, tax.name)) + return super()._post(soft) + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _get_product_accounts(self): + """ As taxes with a different rate need a different income/expense account, we add this logic in case people only use + invoicing to not be blocked by the above constraint""" + result = super(ProductTemplate, self)._get_product_accounts() + company = self.env.company + if company.country_id.code == "DE": + if not self.property_account_income_id: + taxes = self.taxes_id.filtered(lambda t: t.company_id == company) + if not result['income'] or (result['income'].tax_ids and taxes and taxes[0] not in result['income'].tax_ids): + result['income'] = self.env['account.account'].search([('internal_group', '=', 'income'), ('deprecated', '=', False), + ('tax_ids', 'in', taxes.ids)], limit=1) + if not self.property_account_expense_id: + supplier_taxes = self.supplier_taxes_id.filtered(lambda t: t.company_id == company) + if not result['expense'] or (result['expense'].tax_ids and supplier_taxes and supplier_taxes[0] not in result['expense'].tax_ids): + result['expense'] = self.env['account.account'].search([('internal_group', '=', 'expense'), ('deprecated', '=', False), + ('tax_ids', 'in', supplier_taxes.ids)], limit=1) + return result diff --git a/addons/l10n_de/models/ir_actions_report.py b/addons/l10n_de/models/ir_actions_report.py new file mode 100644 index 00000000..bc3c499b --- /dev/null +++ b/addons/l10n_de/models/ir_actions_report.py @@ -0,0 +1,10 @@ +from odoo import models + + +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report' + + def _get_rendering_context(self, docids, data): + data = super()._get_rendering_context(docids, data) + data['din_header_spacing'] = self.get_paperformat().header_spacing + return data |
