Expose shipments_returns constructors and add missing relate from shipment to purchase
issue7016 review37891003
This commit is contained in:
+38
-15
@@ -27,7 +27,8 @@ __all__ = ['Purchase', 'PurchaseIgnoredInvoice',
|
||||
'PurchaseRecreadtedInvoice', 'PurchaseLine', 'PurchaseLineTax',
|
||||
'PurchaseLineIgnoredMove', 'PurchaseLineRecreatedMove', 'PurchaseReport',
|
||||
'OpenSupplier', 'HandleShipmentExceptionAsk', 'HandleShipmentException',
|
||||
'HandleInvoiceExceptionAsk', 'HandleInvoiceException']
|
||||
'HandleInvoiceExceptionAsk', 'HandleInvoiceException',
|
||||
'get_shipments_returns', 'search_shipments_returns']
|
||||
|
||||
_STATES = {
|
||||
'readonly': Eval('state') != 'draft',
|
||||
@@ -44,6 +45,36 @@ STATES = [
|
||||
]
|
||||
|
||||
|
||||
def get_shipments_returns(model_name):
|
||||
"Computes the returns or shipments"
|
||||
def method(self, name):
|
||||
Model = Pool().get(model_name)
|
||||
shipments = set()
|
||||
for line in self.lines:
|
||||
for move in line.moves:
|
||||
if isinstance(move.shipment, Model):
|
||||
shipments.add(move.shipment.id)
|
||||
return list(shipments)
|
||||
return method
|
||||
|
||||
|
||||
def search_shipments_returns(model_name):
|
||||
"Search on shipments or returns"
|
||||
def method(self, name, clause):
|
||||
nested = clause[0].lstrip(name)
|
||||
if nested:
|
||||
return [('lines.moves.shipment' + nested,)
|
||||
+ tuple(clause[1:3]) + (model_name,) + tuple(clause[3:])]
|
||||
else:
|
||||
if isinstance(clause[2], basestring):
|
||||
target = 'rec_name'
|
||||
else:
|
||||
target = 'id'
|
||||
return [('lines.moves.shipment.' + target,)
|
||||
+ tuple(clause[1:3]) + (model_name,)]
|
||||
return classmethod(method)
|
||||
|
||||
|
||||
class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin):
|
||||
'Purchase'
|
||||
__name__ = 'purchase.purchase'
|
||||
@@ -155,10 +186,10 @@ class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin):
|
||||
('exception', 'Exception'),
|
||||
], 'Shipment State', readonly=True, required=True)
|
||||
shipments = fields.Function(fields.One2Many('stock.shipment.in', None,
|
||||
'Shipments'), 'get_shipments')
|
||||
'Shipments'), 'get_shipments', searcher='search_shipments')
|
||||
shipment_returns = fields.Function(
|
||||
fields.One2Many('stock.shipment.in.return', None, 'Shipment Returns'),
|
||||
'get_shipment_returns')
|
||||
'get_shipment_returns', searcher='search_shipment_returns')
|
||||
moves = fields.One2Many('stock.move', 'purchase', 'Moves', readonly=True)
|
||||
|
||||
@classmethod
|
||||
@@ -540,21 +571,13 @@ class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin):
|
||||
'invoice_state': state,
|
||||
})
|
||||
|
||||
def get_shipments_returns(model_name):
|
||||
"Computes the returns or shipments"
|
||||
def method(self, name):
|
||||
Model = Pool().get(model_name)
|
||||
shipments = set()
|
||||
for line in self.lines:
|
||||
for move in line.moves:
|
||||
if isinstance(move.shipment, Model):
|
||||
shipments.add(move.shipment.id)
|
||||
return list(shipments)
|
||||
return method
|
||||
|
||||
get_shipments = get_shipments_returns('stock.shipment.in')
|
||||
get_shipment_returns = get_shipments_returns('stock.shipment.in.return')
|
||||
|
||||
search_shipments = search_shipments_returns('stock.shipment.in')
|
||||
search_shipment_returns = search_shipments_returns(
|
||||
'stock.shipment.in.return')
|
||||
|
||||
def get_shipment_state(self):
|
||||
'''
|
||||
Return the shipment state for the purchase.
|
||||
|
||||
@@ -33,5 +33,58 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_purchase_shipments_relate">
|
||||
<field name="name">Purchases</field>
|
||||
<field name="res_model">purchase.purchase</field>
|
||||
<field name="domain"
|
||||
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('shipments', '=', Eval('active_id')), ('shipments', 'in', Eval('active_ids')))]"
|
||||
pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_purchase_shipments_relate_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="purchase_view_tree"/>
|
||||
<field name="act_window" ref="act_purchase_shipments_relate"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_purchase_shipments_relate_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="purchase_view_form"/>
|
||||
<field name="act_window" ref="act_purchase_shipments_relate"/>
|
||||
</record>
|
||||
<record model="ir.action.keyword"
|
||||
id="act_purchase_shipments_relate_keyword">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">stock.shipment.in,-1</field>
|
||||
<field name="action" ref="act_purchase_shipments_relate"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_purchase_shipment_returns_relate">
|
||||
<field name="name">Purchases</field>
|
||||
<field name="res_model">purchase.purchase</field>
|
||||
<field name="domain"
|
||||
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('shipment_returns', '=', Eval('active_id')), ('shipment_returns', 'in', Eval('active_ids')))]"
|
||||
pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_purchase_shipment_returns_relate_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="purchase_view_tree"/>
|
||||
<field name="act_window" ref="act_purchase_shipment_returns_relate"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_purchase_shipment_returns_relate_view2">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="purchase_view_form"/>
|
||||
<field name="act_window" ref="act_purchase_shipment_returns_relate"/>
|
||||
</record>
|
||||
<record model="ir.action.keyword"
|
||||
id="act_purchase_shipment_returns_relate_keyword">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">stock.shipment.in.return,-1</field>
|
||||
<field name="action" ref="act_purchase_shipment_returns_relate"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
||||
Reference in New Issue
Block a user