Improve open supplier:

- no need to sort ids for domain
- avoid duplicate ids in domain
- use the wizard name as action name
- don't create object in relationship module
This commit is contained in:
Cédric Krier committed 2008-05-29 09:38:37 +02:00
1 parent a3b2dbbeff
commit d2341ea78a
6 files changed
+57 -62

No files matched your search

-1
View File
@@ -25,4 +25,3 @@
##############################################################################
from purchase import *
from party import *
-1
View File
@@ -20,6 +20,5 @@
],
'xml': [
'purchase.xml',
'party.xml',
],
}
-40
View File
@@ -1,40 +0,0 @@
from trytond.wizard import Wizard
class OpenSupplier(Wizard):
'Open Suppliers'
_name = 'relationship.party.open_supplier'
states = {
'init': {
'result': {
'type': 'action',
'action': '_action_open',
'state': 'end',
},
},
}
def _action_open(self, cursor, user, datas, context=None):
model_data_obj = self.pool.get('ir.model.data')
act_window_obj = self.pool.get('ir.action.act_window')
model_data_ids = model_data_obj.search(cursor, user, [
('fs_id', '=', 'act_party_form'),
('module', '=', 'relationship'),
], limit=1, context=context)
model_data = model_data_obj.browse(cursor, user, model_data_ids[0],
context=context)
res = act_window_obj.read(cursor, user, model_data.db_id,
context=context)
cursor.execute(
"SELECT party, max(purchase_date) FROM purchase_purchase "\
"GROUP BY party "\
"ORDER BY max(purchase_date) DESC"
)
suppliers = [line[0] for line in cursor.fetchall()]
domain = eval( res.get('domain') or "[]" )
domain.append(('id', 'in', suppliers))
res['domain'] = str(domain)
return res
OpenSupplier()
-20
View File
@@ -1,20 +0,0 @@
<?xml version="1.0"?>
<tryton>
<data>
<record model="ir.action.wizard" id="act_open_supplier">
<field name="name">Active Suppliers</field>
<field name="wiz_name">relationship.party.open_supplier</field>
</record>
<record model="ir.action.keyword" id="act_open_supplier_keyword1">
<field name="action" ref="act_open_supplier"/>
<field name="keyword">form_action</field>
<field name="model">relationship.party,0</field>
</record>
<menuitem name="Suppliers"
parent="relationship.menu_party_form"
action="act_open_supplier"
type="wizard"
icon="STOCK_JUSTIFY_FILL"
id="menu_open_supplier"/>
</data>
</tryton>
+46
View File
@@ -5,6 +5,7 @@ from decimal import Decimal
import datetime
from trytond.netsvc import LocalService
from trytond.report import CompanyReport
from trytond.wizard import Wizard
_STATES = {
'readonly': "state != 'draft'",
@@ -917,3 +918,48 @@ class Move(OSV):
return res
Move()
class OpenSupplier(Wizard):
'Open Suppliers'
_name = 'purchase.open_supplier'
states = {
'init': {
'result': {
'type': 'action',
'action': '_action_open',
'state': 'end',
},
},
}
def _action_open(self, cursor, user, datas, context=None):
model_data_obj = self.pool.get('ir.model.data')
act_window_obj = self.pool.get('ir.action.act_window')
wizard_obj = self.pool.get('ir.action.wizard')
model_data_ids = model_data_obj.search(cursor, user, [
('fs_id', '=', 'act_party_form'),
('module', '=', 'relationship'),
], limit=1, context=context)
model_data = model_data_obj.browse(cursor, user, model_data_ids[0],
context=context)
res = act_window_obj.read(cursor, user, model_data.db_id,
context=context)
cursor.execute("SELECT DISTINCT(party) FROM purchase_purchase")
supplier_ids = [line[0] for line in cursor.fetchall()]
res['domain'] = str([('id', 'in', supplier_ids)])
model_data_ids = model_data_obj.search(cursor, user, [
('fs_id', '=', 'act_open_supplier'),
('module', '=', 'purchase'),
], limit=1, context=context)
model_data = model_data_obj.browse(cursor, user, model_data_ids[0],
context=context)
wizard = wizard_obj.browse(cursor, user, model_data.db_id,
context=context)
res['name'] = wizard.name
return res
OpenSupplier()
+11
View File
@@ -728,5 +728,16 @@
]]>
</field>
</record>
<record model="ir.action.wizard" id="act_open_supplier">
<field name="name">Suppliers</field>
<field name="wiz_name">purchase.open_supplier</field>
</record>
<menuitem name="Suppliers"
parent="relationship.menu_party_form"
action="act_open_supplier"
type="wizard"
icon="STOCK_JUSTIFY_FILL"
id="menu_supplier"/>
</data>
</tryton>