select target for incoming invoice number

This commit is contained in:
Frederik Jaeckel 2025-01-07 16:08:44 +01:00
parent a94c678d33
commit e8cceb75c1
6 changed files with 73 additions and 2 deletions

View file

@ -9,6 +9,11 @@ from trytond.pool import PoolMeta
from trytond.model import fields from trytond.model import fields
sel_number_target = [
('reference', "in the 'Reference' field"),
('number', "in the 'Number' field")]
class Configuration(metaclass=PoolMeta): class Configuration(metaclass=PoolMeta):
__name__ = 'document.incoming.configuration' __name__ = 'document.incoming.configuration'
@ -20,6 +25,19 @@ class Configuration(metaclass=PoolMeta):
string='Accept other company', string='Accept other company',
help='Accepts invoices created for a company other ' + help='Accepts invoices created for a company other ' +
'than the current one.') 'than the current one.')
number_target = fields.Selection(
string='Invoice number',
help='Destination for the invoice number of the supplier invoice.',
selection=sel_number_target)
@classmethod
def default_number_target(cls):
""" targetfield for incoming invoice number
Returns:
str: field 'reference'
"""
return 'reference'
@classmethod @classmethod
def default_create_supplier(cls): def default_create_supplier(cls):

View file

@ -311,9 +311,13 @@ class Incoming(metaclass=PoolMeta):
msg='invalid type-code: %(code)s (expect: 380, 381)' % { msg='invalid type-code: %(code)s (expect: 380, 381)' % {
'code': str(inv_code)})) 'code': str(inv_code)}))
invoice.number = self._readxml_getvalue(xmltree, [ invoice_number = self._readxml_getvalue(xmltree, [
'rsm:CrossIndustryInvoice', 'rsm:CrossIndustryInvoice',
'rsm:ExchangedDocument', 'ram:ID']) 'rsm:ExchangedDocument', 'ram:ID'])
if config and config.number_target == 'number':
invoice.number = invoice_number
else:
invoice.reference = invoice_number
# invoice-date # invoice-date
date_path = [ date_path = [
@ -380,6 +384,8 @@ class Incoming(metaclass=PoolMeta):
buyer_party[x].replace('\n', '; ') buyer_party[x].replace('\n', '; ')
for x in buyer_party.keys()]))) for x in buyer_party.keys()])))
# lines of invoice
return invoice return invoice
def _readxml_convertdate(self, date_string): def _readxml_convertdate(self, date_string):

View file

@ -41,3 +41,19 @@ msgstr "anderes Unternehmen akzeptieren"
msgctxt "help:document.incoming.configuration,accept_other_company:" msgctxt "help:document.incoming.configuration,accept_other_company:"
msgid "Accepts invoices created for a company other than the current one." msgid "Accepts invoices created for a company other than the current one."
msgstr "Akzeptiert Rechnungen welche für ein anderes Unternehmen als das aktuelle erstellt wurden." msgstr "Akzeptiert Rechnungen welche für ein anderes Unternehmen als das aktuelle erstellt wurden."
msgctxt "field:document.incoming.configuration,number_target:"
msgid "Invoice number"
msgstr "Rechnungsnummer"
msgctxt "help:document.incoming.configuration,number_target:"
msgid "Destination for the invoice number of the supplier invoice."
msgstr "Ziel für die Rechungsnummer der Lieferantenrechung."
msgctxt "selection:document.incoming.configuration,number_target:"
msgid "in the 'Reference' field"
msgstr "in das 'Referenz'-Feld"
msgctxt "selection:document.incoming.configuration,number_target:"
msgid "in the 'Number' field"
msgstr "in das 'Nummer'-Feld"

View file

@ -33,3 +33,20 @@ msgstr "Accept other company"
msgctxt "help:document.incoming.configuration,accept_other_company:" msgctxt "help:document.incoming.configuration,accept_other_company:"
msgid "Accepts invoices created for a company other than the current one." msgid "Accepts invoices created for a company other than the current one."
msgstr "Accepts invoices created for a company other than the current one." msgstr "Accepts invoices created for a company other than the current one."
msgctxt "field:document.incoming.configuration,number_target:"
msgid "Invoice number"
msgstr "Invoice number"
msgctxt "help:document.incoming.configuration,number_target:"
msgid "Destination for the invoice number of the supplier invoice."
msgstr "Destination for the invoice number of the supplier invoice."
msgctxt "selection:document.incoming.configuration,number_target:"
msgid "in the 'Reference' field"
msgstr "in the 'Reference' field"
msgctxt "selection:document.incoming.configuration,number_target:"
msgid "in the 'Number' field"
msgstr "in the 'Number' field"

View file

@ -129,12 +129,22 @@ class DocumentTestCase(object):
config.create_supplier = True config.create_supplier = True
config.accept_other_company = True config.accept_other_company = True
config.number_target = 'number'
config.save()
# check target of incoming invoice number
invoice = document._process_supplier_invoice()
self.assertEqual(invoice.number, 'RE2024.01234')
self.assertTrue(not hasattr(invoice, 'reference'))
config.number_target = 'reference'
config.save() config.save()
invoice = document._process_supplier_invoice() invoice = document._process_supplier_invoice()
print('\n## invoice:', (invoice,)) print('\n## invoice:', (invoice,))
self.assertEqual(invoice.type, 'in') self.assertEqual(invoice.type, 'in')
self.assertEqual(invoice.number, 'RE2024.01234') self.assertEqual(invoice.reference, 'RE2024.01234')
self.assertTrue(not hasattr(invoice, 'number'))
self.assertEqual(invoice.invoice_date, date(2024, 6, 17)) self.assertEqual(invoice.invoice_date, date(2024, 6, 17))
self.assertEqual(invoice.currency.name, 'usd') self.assertEqual(invoice.currency.name, 'usd')
self.assertEqual(invoice.company.rec_name, 'm-ds') self.assertEqual(invoice.company.rec_name, 'm-ds')

View file

@ -4,9 +4,13 @@
this repository contains the full copyright notices and license terms. --> this repository contains the full copyright notices and license terms. -->
<data> <data>
<xpath expr="/form/field[@name='default_supplier']" position="after"> <xpath expr="/form/field[@name='default_supplier']" position="after">
<label name="number_target"/>
<field name="number_target"/>
<label name="create_supplier"/> <label name="create_supplier"/>
<field name="create_supplier"/> <field name="create_supplier"/>
<label name="accept_other_company"/> <label name="accept_other_company"/>
<field name="accept_other_company"/> <field name="accept_other_company"/>
</xpath> </xpath>
</data> </data>