forked from hbrunn/edi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_invoice_import_config.py
68 lines (63 loc) · 3.15 KB
/
account_invoice_import_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (Alexis de Lattre <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
class AccountInvoiceImportConfig(models.Model):
_name = 'account.invoice.import.config'
_description = 'Configuration for the import of Supplier Invoices'
name = fields.Char(string='Name', required=True)
partner_ids = fields.One2many(
'res.partner', 'invoice_import_id',
string='Partners')
active = fields.Boolean(default=True)
invoice_line_method = fields.Selection([
('1line_no_product', 'Single Line, No Product'),
('1line_static_product', 'Single Line, Static Product'),
('nline_no_product', 'Multi Line, No Product'),
('nline_static_product', 'Multi Line, Static Product'),
('nline_auto_product', 'Multi Line, Auto-selected Product'),
], string='Method for Invoice Line', required=True,
default='1line_no_product',
help="The multi-line methods will not work for PDF invoices "
"that don't have an embedded XML file. "
"The 'Multi Line, Auto-selected Product' method will only work with "
"ZUGFeRD invoices at Comfort or Extended level, not at Basic level.")
company_id = fields.Many2one(
'res.company', string='Company',
ondelete='cascade', required=True,
default=lambda self: self.env['res.company']._company_default_get(
'account.invoice.import.config'))
account_id = fields.Many2one(
'account.account', string='Expense Account',
domain=[('type', 'not in', ('view', 'closed'))])
account_analytic_id = fields.Many2one(
'account.analytic.account', string='Analytic Account',
domain=[('type', '!=', 'view')])
label = fields.Char(
string='Force Description',
help="Force supplier invoice line description")
tax_ids = fields.Many2many(
'account.tax', string='Taxes',
domain=[('type_tax_use', 'in', ('all', 'purchase'))])
static_product_id = fields.Many2one(
'product.product', string='Static Product')
@api.constrains('invoice_line_method', 'account_id', 'static_product_id')
def _check_import_config(self):
for config in self:
if (
config.invoice_line_method == 'static_product' and
not config.static_product_id):
raise ValidationError(_(
"Static Product must be set on the invoice import "
"configuration of supplier '%s' that has a Method "
"for Invoice Line set to 'Static Product'.")
% config.partner_id.name)
if (
config.invoice_line_method == 'no_product' and
not config.account_id):
raise ValidationError(_(
"The Expense Account must be set on the invoice "
"import configuration of supplier '%s' that has a "
"Method for Invoice Line set to 'Without product'.")
% config.partner_id.name)