1 parent
c48e7b36c6
commit
1aa9226401
7 files changed
+23
-52
No files matched your search
@@ -19,8 +19,7 @@ from sql.functions import CurrentTimestamp, Extract
|
||||
from sql.operators import Exists
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.model.modelsql import convert_from
|
||||
from trytond.model import ModelSQL, ModelView, convert_from, fields
|
||||
from trytond.modules.account.exceptions import FiscalYearNotFoundError
|
||||
from trytond.modules.account_eu.account import ECSalesList, ECSalesListContext
|
||||
from trytond.modules.currency.fields import Monetary
|
||||
|
||||
+2
-14
@@ -10,7 +10,7 @@ from trytond import backend
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import (
|
||||
DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique,
|
||||
ValueMixin, fields, sequence_ordered)
|
||||
ValueMixin, convert_from, fields, sequence_ordered)
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval
|
||||
@@ -937,18 +937,6 @@ class Erase(Wizard):
|
||||
Party = pool.get('party.party')
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
def convert_from(table, tables):
|
||||
right, condition = tables[None]
|
||||
if table:
|
||||
table = table.join(right, condition=condition)
|
||||
else:
|
||||
table = right
|
||||
for k, sub_tables in tables.items():
|
||||
if k is None:
|
||||
continue
|
||||
table = convert_from(table, sub_tables)
|
||||
return table
|
||||
|
||||
resources = self.get_resources()
|
||||
parties = replacing = [self.ask.party]
|
||||
with inactive_records():
|
||||
@@ -968,7 +956,7 @@ class Erase(Wizard):
|
||||
Model.write(records, {'active': False})
|
||||
|
||||
tables, where = Model.search_domain(domain, active_test=False)
|
||||
from_ = convert_from(None, tables)
|
||||
from_ = convert_from(None, tables, type_='INNER')
|
||||
table, _ = tables[None]
|
||||
query = from_.select(table.id, where=where)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from sql.aggregate import Min
|
||||
from sql.conditionals import Coalesce
|
||||
|
||||
from trytond.config import config
|
||||
from trytond.model import Index, ModelSQL, ModelView, fields
|
||||
from trytond.model import Index, ModelSQL, ModelView, convert_from, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
@@ -159,21 +159,9 @@ class RelationAll(Relation, ModelView):
|
||||
columns.append(column)
|
||||
reverse_columns.append(reverse_column)
|
||||
|
||||
def convert_from(table, tables):
|
||||
right, condition = tables[None]
|
||||
if table:
|
||||
table = table.join(right, condition=condition)
|
||||
else:
|
||||
table = right
|
||||
for k, sub_tables in tables.items():
|
||||
if k is None:
|
||||
continue
|
||||
table = convert_from(table, sub_tables)
|
||||
return table
|
||||
|
||||
query = convert_from(None, tables).select(*columns)
|
||||
reverse_query = convert_from(None, reverse_tables).select(
|
||||
*reverse_columns)
|
||||
query = convert_from(None, tables, type_='INNER').select(*columns)
|
||||
reverse_query = convert_from(
|
||||
None, reverse_tables, type_='INNER').select(*reverse_columns)
|
||||
return Union(query, reverse_query, all_=True)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -5,26 +5,13 @@ from sql.aggregate import Max
|
||||
from sql.conditionals import Coalesce
|
||||
from sql.functions import CurrentTimestamp, LastValue
|
||||
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.model import ModelSQL, ModelView, convert_from, fields
|
||||
from trytond.modules.product import round_price
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.tools import timezone as tz
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
def convert_from(table, tables):
|
||||
right, condition = tables[None]
|
||||
if table:
|
||||
table = table.join(right, condition=condition)
|
||||
else:
|
||||
table = right
|
||||
for k, sub_tables in tables.items():
|
||||
if k is None:
|
||||
continue
|
||||
table = convert_from(table, sub_tables)
|
||||
return table
|
||||
|
||||
|
||||
class Product(metaclass=PoolMeta):
|
||||
__name__ = 'product.product'
|
||||
|
||||
@@ -121,7 +108,7 @@ class ProductCostHistory(ModelSQL, ModelView):
|
||||
else:
|
||||
cost_price = cls.cost_price.sql_cast(move.cost_price)
|
||||
|
||||
move_history = convert_from(None, tables).select(
|
||||
move_history = convert_from(None, tables, type_='INNER').select(
|
||||
(move.id * 2).as_('id'),
|
||||
move.effective_date.as_('date'),
|
||||
move.product.as_('product'),
|
||||
|
||||
@@ -741,6 +741,15 @@ Additional options are available:
|
||||
* ``begin``: optimize for constant pattern and anchored to the beginning of
|
||||
the string
|
||||
|
||||
|
||||
convert_from
|
||||
------------
|
||||
|
||||
.. method:: convert_from(table, tables[, type_])
|
||||
|
||||
Return a SQL ``FromItem`` constructed by joining ``table`` and :ref:`tables
|
||||
<ref-tables>` using ``type_`` with default value ``LEFT``.
|
||||
|
||||
Workflow
|
||||
========
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from .digits import DigitsMixin
|
||||
from .match import MatchMixin
|
||||
from .model import Model
|
||||
from .modelsingleton import ModelSingleton
|
||||
from .modelsql import Check, Exclude, Index, ModelSQL, Unique
|
||||
from .modelsql import Check, Exclude, Index, ModelSQL, Unique, convert_from
|
||||
from .modelstorage import EvalEnvironment, ModelStorage
|
||||
from .modelview import ModelView
|
||||
from .multivalue import MultiValueMixin, ValueMixin
|
||||
@@ -19,7 +19,7 @@ from .union import UnionMixin
|
||||
from .workflow import Workflow
|
||||
|
||||
__all__ = ['Model', 'ModelView', 'ModelStorage', 'ModelSingleton', 'ModelSQL',
|
||||
'Check', 'Unique', 'Exclude', 'Index',
|
||||
'Check', 'Unique', 'Exclude', 'Index', 'convert_from',
|
||||
'Workflow', 'DictSchemaMixin', 'MatchMixin', 'UnionMixin', 'dualmethod',
|
||||
'MultiValueMixin', 'ValueMixin', 'SymbolMixin', 'DigitsMixin',
|
||||
'EvalEnvironment', 'sequence_ordered', 'sort', 'DeactivableMixin', 'tree',
|
||||
|
||||
@@ -2061,17 +2061,17 @@ class ModelSQL(ModelStorage):
|
||||
transaction.lock_table(cls._table)
|
||||
|
||||
|
||||
def convert_from(table, tables):
|
||||
def convert_from(table, tables, type_='LEFT'):
|
||||
# Don't nested joins as SQLite doesn't support
|
||||
right, condition = tables[None]
|
||||
if table:
|
||||
table = table.join(right, 'LEFT', condition)
|
||||
table = table.join(right, type_, condition)
|
||||
else:
|
||||
table = right
|
||||
for k, sub_tables in tables.items():
|
||||
if k is None:
|
||||
continue
|
||||
table = convert_from(table, sub_tables)
|
||||
table = convert_from(table, sub_tables, type_=type_)
|
||||
return table
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user