Migrate from user to employee

This commit is contained in:
Sergi Almacellas Abellana 2013-06-28 10:29:02 +02:00
parent 9179c05d17
commit 30dbc57d19
5 changed files with 36 additions and 10 deletions

View File

@ -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"

View File

@ -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
View File

@ -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

View File

@ -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=&quot;other&quot;]/label[@name=&quot;company&quot;]"
position="before">
<label name="salesman"/>
<field name="salesman"/>
<label name="employee"/>
<field name="employee"/>
</xpath>
</data>
</data>

View File

@ -4,6 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<data>
<xpath expr="/tree/field[@name=&quot;state&quot;]"
position="after">
<field name="salesman"/>
<field name="employee"/>
</xpath>
</data>