configuration: add setting for product-categories
This commit is contained in:
parent
1b440525ac
commit
5d68a2c2b4
6 changed files with 117 additions and 3 deletions
|
@ -5,11 +5,12 @@
|
|||
|
||||
from trytond.pool import Pool
|
||||
from .document import Incoming
|
||||
from .configuration import Configuration
|
||||
from .configuration import Configuration, ConfigProductcategoryRel
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Configuration,
|
||||
ConfigProductcategoryRel,
|
||||
Incoming,
|
||||
module='document_incoming_invoice_xml', type_='model')
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.model import fields, ModelSQL
|
||||
|
||||
|
||||
sel_number_target = [
|
||||
|
@ -29,6 +29,11 @@ class Configuration(metaclass=PoolMeta):
|
|||
string='Invoice number',
|
||||
help='Destination for the invoice number of the supplier invoice.',
|
||||
selection=sel_number_target)
|
||||
product_category = fields.Many2Many(
|
||||
string='Categories', origin='config', target='category',
|
||||
help='Categories used to determine tax and accounts for a product ' +
|
||||
'on an invoice line.',
|
||||
relation_name='document.incoming.confprodcat_rel')
|
||||
|
||||
@classmethod
|
||||
def default_number_target(cls):
|
||||
|
@ -58,3 +63,18 @@ class Configuration(metaclass=PoolMeta):
|
|||
return False
|
||||
|
||||
# end Configuration
|
||||
|
||||
|
||||
class ConfigProductcategoryRel(ModelSQL):
|
||||
'Configuration - Product Category - Relation'
|
||||
__name__ = 'document.incoming.confprodcat_rel'
|
||||
|
||||
config = fields.Many2One(
|
||||
string='Configuration', required=True,
|
||||
ondelete='CASCADE', model_name='document.incoming.configuration')
|
||||
category = fields.Many2One(
|
||||
string='Category', required=True,
|
||||
domain=[('accounting', '=', True)],
|
||||
ondelete='CASCADE', model_name='product.category')
|
||||
|
||||
# end ConfigProductcategoryRel
|
||||
|
|
24
locale/de.po
24
locale/de.po
|
@ -57,3 +57,27 @@ msgstr "in das 'Referenz'-Feld"
|
|||
msgctxt "selection:document.incoming.configuration,number_target:"
|
||||
msgid "in the 'Number' field"
|
||||
msgstr "in das 'Nummer'-Feld"
|
||||
|
||||
msgctxt "field:document.incoming.configuration,product_category:"
|
||||
msgid "Categories"
|
||||
msgstr "Produktkategorien"
|
||||
|
||||
msgctxt "help:document.incoming.configuration,product_category:"
|
||||
msgid "Categories used to determine tax and accounts for a product on an invoice line."
|
||||
msgstr "Kategorien zur Ermittlung von Steuer und Konten für ein Produkt auf einer Rechnungszeile."
|
||||
|
||||
|
||||
#####################################
|
||||
# document.incoming.confprodcat_rel #
|
||||
#####################################
|
||||
msgctxt "model:document.incoming.confprodcat_rel:"
|
||||
msgid "Configuration - Product Category - Relation"
|
||||
msgstr "Konfiguration "
|
||||
|
||||
msgctxt "field:document.incoming.confprodcat_rel,config:"
|
||||
msgid "Configuration"
|
||||
msgstr "konfiguration"
|
||||
|
||||
msgctxt "field:document.incoming.confprodcat_rel,category:"
|
||||
msgid "Category"
|
||||
msgstr "Kategorie"
|
||||
|
|
20
locale/en.po
20
locale/en.po
|
@ -50,3 +50,23 @@ msgctxt "selection:document.incoming.configuration,number_target:"
|
|||
msgid "in the 'Number' field"
|
||||
msgstr "in the 'Number' field"
|
||||
|
||||
msgctxt "field:document.incoming.configuration,product_category:"
|
||||
msgid "Categories"
|
||||
msgstr "Categories"
|
||||
|
||||
msgctxt "help:document.incoming.configuration,product_category:"
|
||||
msgid "Categories used to determine tax and accounts for a product on an invoice line."
|
||||
msgstr "Categories used to determine tax and accounts for a product on an invoice line."
|
||||
|
||||
msgctxt "model:document.incoming.confprodcat_rel:"
|
||||
msgid "Configuration - Product Category - Relation"
|
||||
msgstr "Configuration - Product Category - Relation"
|
||||
|
||||
msgctxt "field:document.incoming.confprodcat_rel,config:"
|
||||
msgid "Configuration"
|
||||
msgstr "Configuration"
|
||||
|
||||
msgctxt "field:document.incoming.confprodcat_rel,category:"
|
||||
msgid "Category"
|
||||
msgstr "Category"
|
||||
|
||||
|
|
|
@ -64,6 +64,48 @@ class DocumentTestCase(object):
|
|||
fisc_year.save()
|
||||
FiscalYear.create_period([fisc_year])
|
||||
|
||||
def prep_prodcat_category(self, company):
|
||||
""" create product category
|
||||
"""
|
||||
pool = Pool()
|
||||
ProdCat = pool.get('product.category')
|
||||
Account = pool.get('account.account')
|
||||
Tax = pool.get('account.tax')
|
||||
|
||||
# get accounts expense/revenue
|
||||
acc_exp, acc_rev, acc_tax, = Account.search([
|
||||
('name', 'in', ['Main Revenue', 'Main Expense', 'Main Tax'])
|
||||
], order=[('name', 'ASC')])
|
||||
self.assertEqual(acc_exp.name, 'Main Expense')
|
||||
self.assertEqual(acc_rev.name, 'Main Revenue')
|
||||
self.assertEqual(acc_tax.name, 'Main Tax')
|
||||
|
||||
# check tax
|
||||
tax, = Tax.search([])
|
||||
self.assertEqual(tax.name, '20% VAT')
|
||||
self.assertEqual(tax.invoice_account.name, 'Main Tax')
|
||||
self.assertEqual(tax.credit_note_account.name, 'Main Tax')
|
||||
|
||||
p_cat, = ProdCat.create([{
|
||||
'name': 'Accounting',
|
||||
'accounting': True,
|
||||
'account_parent': False,
|
||||
'account_expense': acc_exp.id,
|
||||
'account_revenue': acc_rev.id,
|
||||
'taxes_parent': False,
|
||||
'customer_taxes': [('add', [tax.id])],
|
||||
'supplier_taxes': [('add', [tax.id])],
|
||||
}])
|
||||
self.assertEqual(p_cat.name, 'Accounting')
|
||||
self.assertEqual(p_cat.accounting, True)
|
||||
self.assertEqual(p_cat.account_parent, False)
|
||||
self.assertEqual(p_cat.taxes_parent, False)
|
||||
self.assertEqual(p_cat.account_expense.name, 'Main Expense')
|
||||
self.assertEqual(p_cat.account_revenue.name, 'Main Revenue')
|
||||
self.assertEqual(p_cat.customer_taxes[0].name, '20% VAT')
|
||||
self.assertEqual(p_cat.supplier_taxes[0].name, '20% VAT')
|
||||
return p_cat
|
||||
|
||||
@with_transaction()
|
||||
def test_xmldoc_import_facturx(self):
|
||||
""" create incoming-document, load xml, detect type
|
||||
|
@ -79,11 +121,16 @@ class DocumentTestCase(object):
|
|||
create_chart(company=company, tax=True)
|
||||
self.prep_fiscalyear(company)
|
||||
|
||||
config = Configuration()
|
||||
product_category = self.prep_prodcat_category(company)
|
||||
config = Configuration(
|
||||
product_category=[product_category])
|
||||
config.save()
|
||||
|
||||
self.assertEqual(config.create_supplier, True)
|
||||
self.assertEqual(config.accept_other_company, False)
|
||||
self.assertEqual(config.number_target, 'reference')
|
||||
self.assertEqual(len(config.product_category), 1)
|
||||
self.assertEqual(config.product_category[0].name, 'Accounting')
|
||||
|
||||
to_create = []
|
||||
with open(os.path.join(
|
||||
|
|
|
@ -12,5 +12,7 @@
|
|||
<label name="accept_other_company"/>
|
||||
<field name="accept_other_company"/>
|
||||
|
||||
<field name="product_category" colspan="4"/>
|
||||
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in a new issue