mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
Remove patch for contract_invoice already applied
This commit is contained in:
parent
c923e4687e
commit
99a435d396
|
@ -1,332 +0,0 @@
|
|||
Index: CHANGELOG
|
||||
===================================================================
|
||||
|
||||
--- a/modules/contract_invoice/CHANGELOG
|
||||
+++ b/modules/contract_invoice/CHANGELOG
|
||||
@@ -1,2 +1,10 @@
|
||||
+* Allow to generate lines directly from contract
|
||||
+
|
||||
+Version 3.2.0 - 2014-05-22
|
||||
+
|
||||
+Version 3.0.0 - 2013-10-25
|
||||
+
|
||||
+Version 2.8.0 - 2013-04-26
|
||||
+
|
||||
Version 2.6.0 - 2012-11-29
|
||||
* Initial release
|
||||
|
||||
Index: contract.py
|
||||
===================================================================
|
||||
|
||||
--- a/modules/contract_invoice/contract.py
|
||||
+++ b/modules/contract_invoice/contract.py
|
||||
@@ -1,11 +1,13 @@
|
||||
#This file is part of contract_invoice module for Tryton.
|
||||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
+from dateutil.relativedelta import relativedelta
|
||||
+import datetime
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
+from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
-from dateutil.relativedelta import relativedelta
|
||||
-import datetime
|
||||
+from trytond import backend
|
||||
|
||||
|
||||
__all__ = ['ContractServiceProduct', 'Contract', 'ContractInvoiceLine']
|
||||
@@ -25,11 +27,20 @@
|
||||
fields.One2Many('account.invoice.line', None, 'Invoice Lines'),
|
||||
'get_account_invoice_lines')
|
||||
|
||||
+ @classmethod
|
||||
+ def __setup__(cls):
|
||||
+ super(Contract, cls).__setup__()
|
||||
+ cls._buttons.update({
|
||||
+ 'create_lines': {
|
||||
+ 'invisible': Eval('state') != 'active',
|
||||
+ },
|
||||
+ })
|
||||
+
|
||||
def get_account_invoice_lines(self, name):
|
||||
- ContractInvoiceLine = Pool().get('contract.invoice.line')
|
||||
- invoice_lines = ContractInvoiceLine.get_account_invoice_line(
|
||||
- self.contract_invoice_lines, None)
|
||||
- return invoice_lines.values()
|
||||
+ invoice_lines = []
|
||||
+ for line in self.contract_invoice_lines:
|
||||
+ invoice_lines.extend([i.id for i in line.account_invoice_line])
|
||||
+ return invoice_lines
|
||||
|
||||
@classmethod
|
||||
def copy(cls, contracts, default=None):
|
||||
@@ -42,8 +53,7 @@
|
||||
@classmethod
|
||||
def active(cls, contracts):
|
||||
super(Contract, cls).active(contracts)
|
||||
- for contract in contracts:
|
||||
- cls.set_contract_lines(contract)
|
||||
+ cls.create_lines(contracts)
|
||||
|
||||
@classmethod
|
||||
def get_products(cls, contract):
|
||||
@@ -84,68 +94,54 @@
|
||||
return start_date, end_date
|
||||
|
||||
@classmethod
|
||||
- def set_contract_lines(cls, contract):
|
||||
+ @ModelView.button
|
||||
+ def create_lines(cls, contracts):
|
||||
"""
|
||||
- Generate Account invoice Lines from contract
|
||||
+ Generate the missing lines for the contracts
|
||||
+ - It generates the contract lines depending on today date
|
||||
+ - It generates the missing invoice lines for the given contracts
|
||||
"""
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
- Lang = pool.get('ir.lang')
|
||||
InvoiceLine = pool.get('account.invoice.line')
|
||||
ContractInvoiceLine = pool.get('contract.invoice.line')
|
||||
|
||||
- if contract.party.lang:
|
||||
- lang = contract.party.lang
|
||||
- else:
|
||||
- language = Transaction().language
|
||||
- languages = Lang.search([('code', '=', language)])
|
||||
- if not languages:
|
||||
- languages = Lang.search([('code', '=', 'en_US')])
|
||||
- lang = languages[0]
|
||||
-
|
||||
- today = Date.today()
|
||||
- create_line = True
|
||||
- while create_line:
|
||||
+ to_create = []
|
||||
+ for contract in contracts:
|
||||
lines = ContractInvoiceLine.search([
|
||||
('contract', '=', contract),
|
||||
], order=[('end_date', 'DESC')], limit=1)
|
||||
last_date = lines and lines[0].end_date or \
|
||||
contract.start_date - datetime.timedelta(days=1)
|
||||
- if last_date >= today:
|
||||
- create_line = False
|
||||
- else:
|
||||
+ today = Date.today()
|
||||
+ while last_date <= today:
|
||||
start_date, end_date = cls.compute_date_interval(contract,
|
||||
last_date)
|
||||
+ last_date = end_date
|
||||
+ for line in cls.get_products(contract):
|
||||
+ # Create Contract Invoice Line
|
||||
+ contract_invoice_line = ContractInvoiceLine()
|
||||
+ contract_invoice_line.compute_date = today
|
||||
+ contract_invoice_line.start_date = start_date
|
||||
+ contract_invoice_line.end_date = end_date
|
||||
+ contract_invoice_line.quantity = line['qty']
|
||||
+ contract_invoice_line.product = line['product']
|
||||
+ contract_invoice_line.description = line['desc']
|
||||
+ contract_invoice_line.contract = contract
|
||||
+ to_create.append(contract_invoice_line._save_values)
|
||||
+ if to_create:
|
||||
+ ContractInvoiceLine.create(to_create)
|
||||
|
||||
- with Transaction().set_user(0, set_context=True):
|
||||
- for line in cls.get_products(contract):
|
||||
-
|
||||
- # Create Contract Invoice Line
|
||||
- contract_invoice_line = ContractInvoiceLine()
|
||||
- contract_invoice_line.compute_date = today
|
||||
- contract_invoice_line.start_date = start_date
|
||||
- contract_invoice_line.end_date = end_date
|
||||
- contract_invoice_line.quantity = line['qty']
|
||||
- contract_invoice_line.product = line['product']
|
||||
- contract_invoice_line.contract = contract
|
||||
- contract_invoice_line.save()
|
||||
-
|
||||
- # Create Account Invoice Line
|
||||
- start = Lang.strftime(start_date, lang.code, lang.date)
|
||||
- end = Lang.strftime(end_date, lang.code, lang.date)
|
||||
- invoice_line = InvoiceLine.get_invoice_line_product(
|
||||
- party=contract.party,
|
||||
- product=line['product'],
|
||||
- qty=line['qty'],
|
||||
- desc=start + '-' + end + '. ' + line['desc'])
|
||||
- invoice_line.invoice_type = 'out_invoice'
|
||||
- invoice_line.origin = contract_invoice_line
|
||||
-
|
||||
- with Transaction().set_context({
|
||||
- 'invoice_type': 'out_invoice',
|
||||
- 'standalone': True,
|
||||
- }):
|
||||
- invoice_line.save()
|
||||
+ to_create = []
|
||||
+ # Create Account Invoice Line
|
||||
+ with Transaction().set_user(0, set_context=True):
|
||||
+ for contract in contracts:
|
||||
+ for contract_line in contract.contract_invoice_lines:
|
||||
+ invoice_line = contract_line._get_invoice_line()
|
||||
+ if invoice_line:
|
||||
+ to_create.append(invoice_line._save_values)
|
||||
+ if to_create:
|
||||
+ InvoiceLine.create(to_create)
|
||||
|
||||
@classmethod
|
||||
def generate_contract_lines(cls):
|
||||
@@ -158,12 +154,12 @@
|
||||
Date = pool.get('ir.date')
|
||||
today = Date.today()
|
||||
|
||||
- for contract in cls.search([
|
||||
+ contracts = cls.search([
|
||||
('state', '=', 'active'),
|
||||
('start_date', '<=', today),
|
||||
['OR', ('end_date', '>=', today), ('end_date', '=', None)],
|
||||
- ]):
|
||||
- cls.set_contract_lines(contract)
|
||||
+ ])
|
||||
+ cls.create_lines(contracts)
|
||||
return True
|
||||
|
||||
|
||||
@@ -178,35 +174,91 @@
|
||||
product = fields.Many2One('product.product', 'Product')
|
||||
contract = fields.Many2One('contract.contract', 'Contract',
|
||||
ondelete='CASCADE')
|
||||
- account_invoice_line = fields.Function(fields.Many2One(
|
||||
- 'account.invoice.line', 'Invoice Line'),
|
||||
- 'get_account_invoice_line')
|
||||
+ account_invoice_line = fields.One2Many('account.invoice.line',
|
||||
+ 'origin', 'Invoice Line')
|
||||
invoiced = fields.Function(fields.Boolean('Invoiced'),
|
||||
'get_invoiced')
|
||||
+ description = fields.Char('Description')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ContractInvoiceLine, cls).__setup__()
|
||||
cls._order.insert(0, ('end_date', 'DESC'))
|
||||
|
||||
+ @classmethod
|
||||
+ def __register__(cls, module_name):
|
||||
+ pool = Pool()
|
||||
+ TableHandler = backend.get('TableHandler')
|
||||
+ Contract = pool.get('contract.contract')
|
||||
+ ServiceProduct = pool.get('contract.service.product')
|
||||
+ cursor = Transaction().cursor
|
||||
+ table = TableHandler(cursor, cls, module_name)
|
||||
+ update_descriptions = False
|
||||
+ if not table.column_exist('description'):
|
||||
+ update_descriptions = True
|
||||
+ super(ContractInvoiceLine, cls).__register__(module_name)
|
||||
+
|
||||
+ #Migration from 3.2: Copy description field from service product
|
||||
+ if update_descriptions:
|
||||
+ table = cls.__table__()
|
||||
+ contract = Contract.__table__()
|
||||
+ service_product = ServiceProduct.__table__()
|
||||
+ query = table.update(columns=[table.description],
|
||||
+ values=[service_product.description],
|
||||
+ from_=[contract, service_product], where=(
|
||||
+ (table.contract == contract.id) &
|
||||
+ (service_product.service == contract.service) &
|
||||
+ (table.product == service_product.product)))
|
||||
+ cursor.execute(*query)
|
||||
+
|
||||
@staticmethod
|
||||
def default_quantity():
|
||||
return 1
|
||||
|
||||
- @classmethod
|
||||
- def get_account_invoice_line(cls, contract_lines, name):
|
||||
- InvoiceLine = Pool().get('account.invoice.line')
|
||||
- invoice_lines = InvoiceLine.search([
|
||||
- ('origin', 'in', [
|
||||
- 'contract.invoice.line,%s' % cl.id for cl in contract_lines
|
||||
- ]),
|
||||
- ])
|
||||
- result = dict((cl.id, None) for cl in contract_lines)
|
||||
- result.update(dict((il.origin.id, il.id) for il in invoice_lines))
|
||||
- return result
|
||||
+ def get_invoiced(self, name):
|
||||
+ for line in self.account_invoice_line:
|
||||
+ if line.invoice:
|
||||
+ return True
|
||||
+ return False
|
||||
|
||||
- def get_invoiced(self, name):
|
||||
- if not (self.account_invoice_line and
|
||||
- self.account_invoice_line.invoice):
|
||||
- return False
|
||||
- return True
|
||||
+ def _get_invoice_line(self):
|
||||
+ 'Returns the invoice line to create for the current line'
|
||||
+ pool = Pool()
|
||||
+ InvoiceLine = pool.get('account.invoice.line')
|
||||
+ Uom = pool.get('product.uom')
|
||||
+ quantity = self.quantity
|
||||
+ for invoice_line in self.account_invoice_line:
|
||||
+ quantity -= Uom.compute_qty(invoice_line.unit,
|
||||
+ invoice_line.quantity, self.product.default_uom)
|
||||
+
|
||||
+ if not quantity:
|
||||
+ return
|
||||
+ description = '%s-%s' % self._get_start_end_date()
|
||||
+ if self.description:
|
||||
+ description += '. %s' % self.description
|
||||
+ invoice_line = InvoiceLine.get_invoice_line_product(
|
||||
+ party=self.contract.party,
|
||||
+ product=self.product,
|
||||
+ qty=quantity,
|
||||
+ desc=description)
|
||||
+ invoice_line.invoice_type = 'out_invoice'
|
||||
+ invoice_line.origin = self
|
||||
+ invoice_line.type = 'line'
|
||||
+ return invoice_line
|
||||
+
|
||||
+ def _get_start_end_date(self):
|
||||
+ pool = Pool()
|
||||
+ Lang = pool.get('ir.lang')
|
||||
+ if self.contract.party.lang:
|
||||
+ lang = self.contract.party.lang
|
||||
+ else:
|
||||
+ language = Transaction().language
|
||||
+ languages = Lang.search([('code', '=', language)])
|
||||
+ if not languages:
|
||||
+ languages = Lang.search([('code', '=', 'en_US')])
|
||||
+ lang = languages[0]
|
||||
+ start = Lang.strftime(self.start_date,
|
||||
+ lang.code, lang.date)
|
||||
+ end = Lang.strftime(self.end_date, lang.code,
|
||||
+ lang.date)
|
||||
+ return start, end
|
||||
|
||||
Index: view/contract_form.xml
|
||||
===================================================================
|
||||
|
||||
--- a/modules/contract_invoice/view/contract_form.xml
|
||||
+++ b/modules/contract_invoice/view/contract_form.xml
|
||||
@@ -8,6 +8,8 @@
|
||||
<page string="Invoice Lines" id="account_invoice_lines">
|
||||
<field name="contract_invoice_lines"/>
|
||||
<field name="account_invoice_lines"/>
|
||||
+ <button name="create_lines" string="Create Lines"
|
||||
+ icon="tryton-ok" colspan="4"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
Index: view/contract_invoice_line_form.xml
|
||||
===================================================================
|
||||
|
||||
--- a/modules/contract_invoice/view/contract_invoice_line_form.xml
|
||||
+++ b/modules/contract_invoice/view/contract_invoice_line_form.xml
|
||||
@@ -17,6 +17,5 @@
|
||||
<field name="product"/>
|
||||
<label name="invoiced"/>
|
||||
<field name="invoiced"/>
|
||||
- <label name="account_invoice_line"/>
|
||||
- <field name="account_invoice_line"/>
|
||||
+ <field name="account_invoice_line" colspan="4"/>
|
||||
</form>
|
||||
|
Loading…
Reference in a new issue