Migrate from user to employee
This commit is contained in:
parent
9179c05d17
commit
30dbc57d19
|
@ -2,7 +2,7 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||||
|
|
||||||
msgctxt "field:sale.sale,salesman:"
|
msgctxt "field:sale.sale,employee:"
|
||||||
msgid "Salesman"
|
msgid "Salesman"
|
||||||
msgstr "Venedor"
|
msgstr "Venedor"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||||
|
|
||||||
msgctxt "field:sale.sale,salesman:"
|
msgctxt "field:sale.sale,employee:"
|
||||||
msgid "Salesman"
|
msgid "Salesman"
|
||||||
msgstr "Vendedor"
|
msgstr "Vendedor"
|
||||||
|
|
||||||
|
|
34
sale.py
34
sale.py
|
@ -3,9 +3,10 @@
|
||||||
# the full copyright notices and license terms.
|
# the full copyright notices and license terms.
|
||||||
|
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import PoolMeta
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
|
from trytond.backend import TableHandler
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -17,12 +18,37 @@ __metaclass__ = PoolMeta
|
||||||
class Sale():
|
class Sale():
|
||||||
__name__ = 'sale.sale'
|
__name__ = 'sale.sale'
|
||||||
|
|
||||||
salesman = fields.Many2One('res.user', 'Salesman',
|
employee = fields.Many2One('company.employee', 'Salesman',
|
||||||
states={
|
states={
|
||||||
'readonly': Eval('state') != 'draft',
|
'readonly': Eval('state') != 'draft',
|
||||||
},
|
},
|
||||||
depends=['state'])
|
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
|
@staticmethod
|
||||||
def default_salesman():
|
def default_employee():
|
||||||
return Transaction().user
|
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
|
||||||
|
|
|
@ -4,7 +4,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
||||||
<data>
|
<data>
|
||||||
<xpath expr="/form/notebook/page[@id="other"]/label[@name="company"]"
|
<xpath expr="/form/notebook/page[@id="other"]/label[@name="company"]"
|
||||||
position="before">
|
position="before">
|
||||||
<label name="salesman"/>
|
<label name="employee"/>
|
||||||
<field name="salesman"/>
|
<field name="employee"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
@ -4,6 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
||||||
<data>
|
<data>
|
||||||
<xpath expr="/tree/field[@name="state"]"
|
<xpath expr="/tree/field[@name="state"]"
|
||||||
position="after">
|
position="after">
|
||||||
<field name="salesman"/>
|
<field name="employee"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue