diff --git a/locale/ca_ES.po b/locale/ca_ES.po index 9582ce2..872c29f 100644 --- a/locale/ca_ES.po +++ b/locale/ca_ES.po @@ -2,7 +2,7 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "field:sale.sale,salesman:" +msgctxt "field:sale.sale,employee:" msgid "Salesman" msgstr "Venedor" diff --git a/locale/es_ES.po b/locale/es_ES.po index 04bf2d6..5a306b9 100644 --- a/locale/es_ES.po +++ b/locale/es_ES.po @@ -2,7 +2,7 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "field:sale.sale,salesman:" +msgctxt "field:sale.sale,employee:" msgid "Salesman" msgstr "Vendedor" diff --git a/sale.py b/sale.py index bb01992..3b6efb6 100644 --- a/sale.py +++ b/sale.py @@ -3,9 +3,10 @@ # the full copyright notices and license terms. from trytond.model import fields -from trytond.pool import PoolMeta +from trytond.pool import PoolMeta, Pool from trytond.transaction import Transaction from trytond.pyson import Eval +from trytond.backend import TableHandler __all__ = [ @@ -17,12 +18,37 @@ __metaclass__ = PoolMeta class Sale(): __name__ = 'sale.sale' - salesman = fields.Many2One('res.user', 'Salesman', + employee = fields.Many2One('company.employee', 'Salesman', states={ 'readonly': Eval('state') != 'draft', }, depends=['state']) + @classmethod + def __register__(cls, module_name): + pool = Pool() + User = pool.get('res.user') + + cursor = Transaction().cursor + table = TableHandler(cursor, cls, module_name) + + super(Sale, cls).__register__(module_name) + + #Migration from 2.8: Salesman from user to employee + if table.column_exist('salesman'): + cursor.execute('update "%s" set employee = "%s".employee from "%s"' + ' where "%s".id = "%s".salesman' % + (cls._table, User._table, + User._table, User._table, cls._table)) + table.column_rename('salesman', 'salesman_deprecated') + @staticmethod - def default_salesman(): - return Transaction().user + def default_employee(): + User = Pool().get('res.user') + + if Transaction().context.get('employee'): + return Transaction().context['employee'] + else: + user = User(Transaction().user) + if user.employee: + return user.employee.id diff --git a/view/sale_form.xml b/view/sale_form.xml index 0b2a335..16068e8 100644 --- a/view/sale_form.xml +++ b/view/sale_form.xml @@ -4,7 +4,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig - - \ No newline at end of file + diff --git a/view/sale_list.xml b/view/sale_list.xml index 3f6c3f9..e09a74a 100644 --- a/view/sale_list.xml +++ b/view/sale_list.xml @@ -4,6 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig - +