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
* Change 2.4.0 version
* Add es_ES locale
* Add ca_ES locale
* setup.py trytond prefix

View File

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

10
README
View File

@ -1,6 +1,8 @@
account_invoice_consecutive
===========================
The account_invoice_consecutive module of the Tryton application platform.
Installing
----------
@ -9,9 +11,13 @@ See INSTALL
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
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.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import Pool
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.
from trytond.model import Workflow, ModelView, ModelSQL
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):
_name = 'account.invoice'
class Invoice:
'Invoice'
__name__ = 'account.invoice'
def __init__(self):
super(Invoice, self).__init__()
self._error_messages.update({
'invalid_number_date': 'You are trying to create invoice '
'%(invoice_number)s with date %(invoice_date)s but '
'%(invoice_count)d invoices exist which have incompatible '
'numbers and dates:\n\n%(invoices)s',
'invalid_number_date_item': 'Number: %(number)s\nDate: '
'%(date)s\n',
@classmethod
def __setup__(cls):
super(Invoice, cls).__setup__()
cls._error_messages.update({
'invalid_number_date': 'You are trying to create '
'%(invoice_number)s invoice, date %(invoice_date)s. '
'There are %(invoice_count)d invoices before this date:'
'\n\n%(invoices)s',
})
def set_number(self, invoice):
pool = Pool()
res = super(Invoice, self).set_number(invoice)
def set_number(self):
# TODO: When do we check this?
#if not invoice.journal_id.check_invoice_lines_tax:
#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.execute("""
SELECT
@ -39,38 +40,19 @@ class Invoice(Workflow, ModelSQL, ModelView):
(number < %s AND invoice_date > %s) OR
(number > %s AND invoice_date < %s)
)
""", (invoice.type, invoice.number, invoice.invoice_date,
invoice.number, invoice.invoice_date))
""", (self.type, self.number, self.invoice_date,
self.number, self.invoice_date))
records = cursor.fetchall()
if records:
limit = 5
language = Transaction().language
lang_obj = pool.get('ir.lang')
lang_id, = lang_obj.search([('code', '=', language)])
lang = lang_obj.browse(lang_id)
error = self._error_messages['invalid_number_date_item']
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])
info = ['%(number)s - %(date)s' % {
'number': record[0],
'date': unicode(record[1]),
} for record in records]
info = '\n'.join(info[:limit])
self.raise_user_error('invalid_number_date', {
'invoice_number': invoice.number,
'invoice_date': lang_obj.strftime(invoice.invoice_date,
lang.code, lang.date),
'invoice_count': len(records),
'invoices': text,
})
return res
Invoice()
'invoice_number': self.number,
'invoice_date': self.invoice_date,
'invoice_count': len(records),
'invoices': info,
})

View File

@ -5,8 +5,15 @@
from setuptools import setup
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 = int(major_version)
minor_version = int(minor_version)
@ -22,10 +29,11 @@ requires.append('trytond >= %s.%s, < %s.%s' %
setup(name='trytond_account_invoice_consecutive',
version=info.get('version', '0.0.1'),
description=info.get('description', ''),
author=info.get('author', ''),
author_email=info.get('email', ''),
url=info.get('website', ''),
description='Tryton module ensures new invoices do not have a date' \
'previous to the latest invoice in the sequence',
author='NaN·tic',
author_email='info@NaN-tic.com',
url='http://www.nan-tic.com',
download_url="https://bitbucket.org/albertnan/account_invoice_consecutive",
package_dir={'trytond.modules.account_invoice_consecutive': '.'},
packages=[
@ -34,7 +42,7 @@ setup(name='trytond_account_invoice_consecutive',
],
package_data={
'trytond.modules.account_invoice_consecutive': info.get('xml', []) \
+ info.get('translation', []),
+ ['tryton.cfg', 'locale/*.po'],
},
classifiers=[
'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: