Migrate from user to employee
This commit is contained in:
parent
9179c05d17
commit
30dbc57d19
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
34
sale.py
34
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
|
||||
|
|
|
@ -4,7 +4,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
<data>
|
||||
<xpath expr="/form/notebook/page[@id="other"]/label[@name="company"]"
|
||||
position="before">
|
||||
<label name="salesman"/>
|
||||
<field name="salesman"/>
|
||||
<label name="employee"/>
|
||||
<field name="employee"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</data>
|
||||
|
|
|
@ -4,6 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
<data>
|
||||
<xpath expr="/tree/field[@name="state"]"
|
||||
position="after">
|
||||
<field name="salesman"/>
|
||||
<field name="employee"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue