Active Record

This commit is contained in:
resteve 2012-10-17 11:18:43 +02:00
parent b0363faed9
commit 0e973f9308
8 changed files with 78 additions and 87 deletions

View File

@ -1,5 +1,10 @@
Version 2.6.0 - 2012-10-16
* Active Record
* Simplify module information with python configuration
Version 2.4.0 - 2012-08-27
* Initial release
* Add tests * Add tests
* Change 2.4.0 version
* Add es_ES locale * Add es_ES locale
* Add ca_ES locale * Add ca_ES locale
* setup.py trytond prefix * setup.py trytond prefix

View File

@ -5,3 +5,4 @@ include COPYRIGHT
include CHANGELOG include CHANGELOG
include LICENSE include LICENSE
include locale/*.po include locale/*.po
include doc/*

10
README
View File

@ -1,6 +1,8 @@
account_invoice_consecutive account_invoice_consecutive
=========================== ===========================
The account_invoice_consecutive module of the Tryton application platform.
Installing Installing
---------- ----------
@ -9,9 +11,13 @@ See INSTALL
Support Support
------- -------
If you encounter any problems please use bitbucket bugtracker: For more information or if you encounter any problems with this module,
please contact the programmers at
https://bitbucket.org/albertnan/account_invoice_consecutive/issues Nan-Tic
--------------
website: http://www.nan-tic.com/
email: info@nan-tic.com
If you encounter any problems with Tryton, please don't hesitate to ask If you encounter any problems with Tryton, please don't hesitate to ask
questions on the Tryton bug tracker, mailing list, wiki or IRC channel: questions on the Tryton bug tracker, mailing list, wiki or IRC channel:

View File

@ -1,5 +1,11 @@
#This file is part account_invoice_consecutive module for Tryton. #This file is part account_invoice_consecutive module for Tryton.
#The COPYRIGHT file at the top level of this repository contains #The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms. #the full copyright notices and license terms.
from trytond.pool import Pool
from .invoice import * from .invoice import *
def register():
Pool.register(
Invoice,
module='account_invoice_consecutive', type_='model')

View File

@ -1,30 +0,0 @@
#This file is part account_invoice_consecutive module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
{
'name': 'Account Invoice Consecutive',
'version': '2.4.0',
'author': 'NaN·tic',
'email': 'info@NaN-tic.com',
'website': 'http://www.tryton.org/',
'description': 'Allows ensuring new invoices do not have a date previous '\
'to the latest invoice in the sequence, as required by the law of '\
'some countries such as Spain.',
'depends': [
'ir',
'account',
'company',
'party',
'product',
'res',
'currency',
'account_product',
'account_invoice',
],
'xml': [
],
'translation': [
'locale/ca_ES.po',
'locale/es_ES.po',
]
}

View File

@ -3,30 +3,31 @@
#the full copyright notices and license terms. #the full copyright notices and license terms.
from trytond.model import Workflow, ModelView, ModelSQL from trytond.model import Workflow, ModelView, ModelSQL
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.pool import Pool from trytond.pool import Pool, PoolMeta
__all__ = ['Invoice']
__metaclass__ = PoolMeta
class Invoice(Workflow, ModelSQL, ModelView): class Invoice:
_name = 'account.invoice' 'Invoice'
__name__ = 'account.invoice'
def __init__(self): @classmethod
super(Invoice, self).__init__() def __setup__(cls):
self._error_messages.update({ super(Invoice, cls).__setup__()
'invalid_number_date': 'You are trying to create invoice ' cls._error_messages.update({
'%(invoice_number)s with date %(invoice_date)s but ' 'invalid_number_date': 'You are trying to create '
'%(invoice_count)d invoices exist which have incompatible ' '%(invoice_number)s invoice, date %(invoice_date)s. '
'numbers and dates:\n\n%(invoices)s', 'There are %(invoice_count)d invoices before this date:'
'invalid_number_date_item': 'Number: %(number)s\nDate: ' '\n\n%(invoices)s',
'%(date)s\n',
}) })
def set_number(self, invoice): def set_number(self):
pool = Pool()
res = super(Invoice, self).set_number(invoice)
# TODO: When do we check this? # TODO: When do we check this?
#if not invoice.journal_id.check_invoice_lines_tax: #if not invoice.journal_id.check_invoice_lines_tax:
#continue #continue
if invoice.type in ('out_invoice', 'out_credit_note'): if self.type in ('out_invoice', 'out_credit_note'):
res = super(Invoice, self).set_number()
cursor = Transaction().cursor cursor = Transaction().cursor
cursor.execute(""" cursor.execute("""
SELECT SELECT
@ -39,38 +40,19 @@ class Invoice(Workflow, ModelSQL, ModelView):
(number < %s AND invoice_date > %s) OR (number < %s AND invoice_date > %s) OR
(number > %s AND invoice_date < %s) (number > %s AND invoice_date < %s)
) )
""", (invoice.type, invoice.number, invoice.invoice_date, """, (self.type, self.number, self.invoice_date,
invoice.number, invoice.invoice_date)) self.number, self.invoice_date))
records = cursor.fetchall() records = cursor.fetchall()
if records: if records:
limit = 5 limit = 5
language = Transaction().language info = ['%(number)s - %(date)s' % {
lang_obj = pool.get('ir.lang') 'number': record[0],
lang_id, = lang_obj.search([('code', '=', language)]) 'date': unicode(record[1]),
lang = lang_obj.browse(lang_id) } for record in records]
error = self._error_messages['invalid_number_date_item'] info = '\n'.join(info[:limit])
translation_obj = pool.get('ir.translation')
message = translation_obj.get_source('account.invoice',
'error', language, error)
if not message:
message = translation_obj.get_source(error, 'error',
language)
if message:
error = message
text = []
records = [error % {
'number': record[0],
'date': lang_obj.strftime(record[1], lang.code,
lang.date),
} for record in records]
text = '\n'.join(records[:limit])
self.raise_user_error('invalid_number_date', { self.raise_user_error('invalid_number_date', {
'invoice_number': invoice.number, 'invoice_number': self.number,
'invoice_date': lang_obj.strftime(invoice.invoice_date, 'invoice_date': self.invoice_date,
lang.code, lang.date), 'invoice_count': len(records),
'invoice_count': len(records), 'invoices': info,
'invoices': text, })
})
return res
Invoice()

View File

@ -5,8 +5,15 @@
from setuptools import setup from setuptools import setup
import re import re
import os
import ConfigParser
info = eval(open('__tryton__.py').read()) config = ConfigParser.ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
for key in ('depends', 'extras_depend', 'xml'):
if key in info:
info[key] = info[key].strip().splitlines()
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2) major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
major_version = int(major_version) major_version = int(major_version)
minor_version = int(minor_version) minor_version = int(minor_version)
@ -22,10 +29,11 @@ requires.append('trytond >= %s.%s, < %s.%s' %
setup(name='trytond_account_invoice_consecutive', setup(name='trytond_account_invoice_consecutive',
version=info.get('version', '0.0.1'), version=info.get('version', '0.0.1'),
description=info.get('description', ''), description='Tryton module ensures new invoices do not have a date' \
author=info.get('author', ''), 'previous to the latest invoice in the sequence',
author_email=info.get('email', ''), author='NaN·tic',
url=info.get('website', ''), author_email='info@NaN-tic.com',
url='http://www.nan-tic.com',
download_url="https://bitbucket.org/albertnan/account_invoice_consecutive", download_url="https://bitbucket.org/albertnan/account_invoice_consecutive",
package_dir={'trytond.modules.account_invoice_consecutive': '.'}, package_dir={'trytond.modules.account_invoice_consecutive': '.'},
packages=[ packages=[
@ -34,7 +42,7 @@ setup(name='trytond_account_invoice_consecutive',
], ],
package_data={ package_data={
'trytond.modules.account_invoice_consecutive': info.get('xml', []) \ 'trytond.modules.account_invoice_consecutive': info.get('xml', []) \
+ info.get('translation', []), + ['tryton.cfg', 'locale/*.po'],
}, },
classifiers=[ classifiers=[
'Development Status :: 5 - Production/Stable', 'Development Status :: 5 - Production/Stable',

13
tryton.cfg Normal file
View File

@ -0,0 +1,13 @@
[tryton]
version=2.6.0
depends:
ir
account
company
party
product
res
currency
account_product
account_invoice
xml: