Remove Property fields
issue2349 review32201002
This commit is contained in:
1 parent
5518f88254
commit
c6eadfa6ef
4 files changed
+120
-35
No files matched your search
@@ -29,6 +29,8 @@ def register():
|
||||
HandleShipmentExceptionAsk,
|
||||
HandleInvoiceExceptionAsk,
|
||||
Configuration,
|
||||
ConfigurationSequence,
|
||||
ConfigurationPurchaseMethod,
|
||||
Invoice,
|
||||
InvoiceLine,
|
||||
Location,
|
||||
|
||||
+110
-16
@@ -1,30 +1,124 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
|
||||
from trytond import backend
|
||||
from trytond.model import (ModelView, ModelSQL, ModelSingleton, ValueMixin,
|
||||
fields)
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tools.multivalue import migrate_property
|
||||
from trytond.modules.company.model import (
|
||||
CompanyMultiValueMixin, CompanyValueMixin)
|
||||
|
||||
__all__ = ['Configuration']
|
||||
__all__ = ['Configuration',
|
||||
'ConfigurationSequence', 'ConfigurationPurchaseMethod']
|
||||
purchase_invoice_method = fields.Selection(
|
||||
'get_purchase_invoice_method', "Invoice Method")
|
||||
|
||||
|
||||
class Configuration(ModelSingleton, ModelSQL, ModelView):
|
||||
def get_purchase_methods(field_name):
|
||||
@classmethod
|
||||
def func(cls):
|
||||
pool = Pool()
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
return Purchase.fields_get([field_name])[field_name]['selection']
|
||||
return func
|
||||
|
||||
|
||||
class Configuration(
|
||||
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
|
||||
'Purchase Configuration'
|
||||
__name__ = 'purchase.configuration'
|
||||
purchase_sequence = fields.Property(fields.Many2One('ir.sequence',
|
||||
'Purchase Sequence', domain=[
|
||||
purchase_sequence = fields.MultiValue(fields.Many2One(
|
||||
'ir.sequence', "Purchase Sequence", required=True,
|
||||
domain=[
|
||||
('company', 'in',
|
||||
[Eval('context', {}).get('company', -1), None]),
|
||||
('code', '=', 'purchase.purchase'),
|
||||
], required=True))
|
||||
purchase_invoice_method = fields.Property(fields.Selection(
|
||||
'get_purchase_invoice_method', 'Invoice Method',
|
||||
states={
|
||||
'required': Bool(Eval('context', {}).get('company')),
|
||||
}))
|
||||
]))
|
||||
purchase_invoice_method = fields.MultiValue(purchase_invoice_method)
|
||||
get_purchase_invoice_method = get_purchase_methods('invoice_method')
|
||||
|
||||
@classmethod
|
||||
def get_purchase_invoice_method(cls):
|
||||
def multivalue_model(cls, field):
|
||||
pool = Pool()
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
return Purchase.fields_get(
|
||||
['invoice_method'])['invoice_method']['selection']
|
||||
if field == 'purchase_invoice_method':
|
||||
return pool.get('purchase.configuration.purchase_method')
|
||||
if field == 'purchase_sequence':
|
||||
return pool.get('purchase.configuration.sequence')
|
||||
return super(Configuration, cls).multivalue_model(field)
|
||||
|
||||
@classmethod
|
||||
def default_purchase_sequence(cls, **pattern):
|
||||
return cls.multivalue_model(
|
||||
'purchase_sequence').default_purchase_sequence()
|
||||
|
||||
@classmethod
|
||||
def default_purchase_invoice_method(cls, **pattern):
|
||||
return cls.multivalue_model(
|
||||
'purchase_invoice_method').default_purchase_invoice_method()
|
||||
|
||||
|
||||
class ConfigurationSequence(ModelSQL, CompanyValueMixin):
|
||||
"Purchase Configuration Sequence"
|
||||
__name__ = 'purchase.configuration.sequence'
|
||||
purchase_sequence = fields.Many2One(
|
||||
'ir.sequence', "Purchase Sequence", required=True,
|
||||
domain=[
|
||||
('company', 'in', [Eval('company', -1), None]),
|
||||
('code', '=', 'purchase.purchase'),
|
||||
],
|
||||
depends=['company'])
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
exist = TableHandler.table_exist(cls._table)
|
||||
|
||||
super(ConfigurationSequence, cls).__register__(module_name)
|
||||
|
||||
if not exist:
|
||||
cls._migrate_property([], [], [])
|
||||
|
||||
@classmethod
|
||||
def _migrate_property(cls, field_names, value_names, fields):
|
||||
field_names.append('purchase_sequence')
|
||||
value_names.append('purchase_sequence')
|
||||
fields.append('company')
|
||||
migrate_property(
|
||||
'purchase.configuration', field_names, cls, value_names,
|
||||
fields=fields)
|
||||
|
||||
@classmethod
|
||||
def default_purchase_sequence(cls):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
return ModelData.get_id('purchase', 'sequence_purchase')
|
||||
|
||||
|
||||
class ConfigurationPurchaseMethod(ModelSQL, ValueMixin):
|
||||
"Purchase Configuration Purchase Method"
|
||||
__name__ = 'purchase.configuration.purchase_method'
|
||||
purchase_invoice_method = purchase_invoice_method
|
||||
get_purchase_invoice_method = get_purchase_methods('invoice_method')
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
exist = TableHandler.table_exist(cls._table)
|
||||
|
||||
super(ConfigurationPurchaseMethod, cls).__register__(module_name)
|
||||
|
||||
if not exist:
|
||||
cls._migrate_property([], [], [])
|
||||
|
||||
@classmethod
|
||||
def _migrate_property(cls, field_names, value_names, fields):
|
||||
field_names.append('purchase_invoice_method')
|
||||
value_names.append('purchase_invoice_method')
|
||||
migrate_property(
|
||||
'purchase.configuration', field_names, cls, value_names,
|
||||
fields=fields)
|
||||
|
||||
@classmethod
|
||||
def default_purchase_invoice_method(cls):
|
||||
return 'order'
|
||||
@@ -22,17 +22,4 @@ this repository contains the full copyright notices and license terms. -->
|
||||
action="act_purchase_configuration_form"
|
||||
id="menu_purchase_configuration" icon="tryton-list"/>
|
||||
</data>
|
||||
<data noupdate="1">
|
||||
<record model="ir.property" id="property_purchase_sequence">
|
||||
<field name="field"
|
||||
search="[('model.model', '=', 'purchase.configuration'), ('name', '=', 'purchase_sequence')]"/>
|
||||
<field name="value" eval="'ir.sequence,' + str(ref('sequence_purchase'))"/>
|
||||
</record>
|
||||
<record model="ir.property"
|
||||
id="property_purchase_invoice_method">
|
||||
<field name="field"
|
||||
search="[('model.model', '=', 'purchase.configuration'), ('name', '=', 'purchase_invoice_method')]" />
|
||||
<field name="value">,order</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+8
-6
@@ -999,8 +999,8 @@ class PurchaseLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
'misses the supplier location for line "%(line)s".'),
|
||||
'missing_account_expense': ('Product "%(product)s" of '
|
||||
'purchase %(purchase)s misses an expense account.'),
|
||||
'missing_account_expense_property': ('Purchase "%(purchase)s" '
|
||||
'misses an "account expense" default property.'),
|
||||
'missing_default_account_expense': ('Purchase "%(purchase)s" '
|
||||
'misses a default "account expense".'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@@ -1247,8 +1247,9 @@ class PurchaseLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
def get_invoice_line(self):
|
||||
'Return a list of invoice line for purchase line'
|
||||
pool = Pool()
|
||||
Property = pool.get('ir.property')
|
||||
InvoiceLine = pool.get('account.invoice.line')
|
||||
AccountConfiguration = pool.get('account.configuration')
|
||||
account_config = AccountConfiguration(1)
|
||||
|
||||
invoice_line = InvoiceLine()
|
||||
invoice_line.type = self.type
|
||||
@@ -1284,12 +1285,13 @@ class PurchaseLine(sequence_ordered(), ModelSQL, ModelView):
|
||||
'purchase': self.purchase.rec_name,
|
||||
})
|
||||
else:
|
||||
for model in ('product.template', 'product.category'):
|
||||
invoice_line.account = Property.get('account_expense', model)
|
||||
for name in ['default_product_account_expense',
|
||||
'default_category_account_expense']:
|
||||
invoice_line.account = account_config.get_multivalue(name)
|
||||
if invoice_line.account:
|
||||
break
|
||||
if not invoice_line.account:
|
||||
self.raise_user_error('missing_account_expense_property',
|
||||
self.raise_user_error('missing_default_account_expense',
|
||||
{'purchase': self.purchase.rec_name})
|
||||
invoice_line.stock_moves = self._get_invoice_line_moves()
|
||||
return [invoice_line]
|
||||
|
||||
Reference in new issue
Block a user