fix stock_mts_mto procurement check method

This commit is contained in:
Florian da Costa
2015-08-12 19:22:57 +02:00
committed by Deivis Laya
parent 14b7fc1f20
commit 6657f96fe4

View File

@@ -19,12 +19,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp import models, api
from openerp import models, api, fields
class ProcurementOrder(models.Model):
_inherit = 'procurement.order'
mts_mto_procurement_id = fields.Many2one(
'procurement.order',
string="Mto+Mts Procurement",
copy=False)
mts_mto_procurement_ids = fields.One2many(
'procurement.order',
'mts_mto_procurement_id',
string="Procurements")
@api.multi
def get_mto_qty_to_order(self):
self.ensure_one()
@@ -52,23 +61,31 @@ class ProcurementOrder(models.Model):
'product_qty': qty,
'product_uos_qty': uos_qty,
'rule_id': rule.id,
'mts_mto_procurement_id': proc.id,
}
@api.model
def _check(self, procurement):
if procurement.rule_id and \
procurement.rule_id.action == 'split_procurement':
if procurement.state == 'running':
cancel_proc_list = [x.state == 'cancel'
for x in procurement.mts_mto_procurement_ids]
done_cancel_test_list = [
x.state in ('done', 'cancel')
for x in procurement.mts_mto_procurement_ids]
if all(cancel_proc_list):
procurement.write({'state': 'cancel'})
elif all(done_cancel_test_list):
return True
return super(ProcurementOrder, self)._check(procurement)
@api.multi
def run(self, autocommit=False):
res = super(ProcurementOrder, self).run(autocommit=autocommit)
for proc in self:
if proc.rule_id and \
proc.rule_id.action == 'split_procurement':
proc.check()
def check(self, autocommit=False):
res = super(ProcurementOrder, self).check(autocommit=autocommit)
for procurement in self:
if procurement.mts_mto_procurement_id:
procurement.mts_mto_procurement_id.check(
autocommit=autocommit)
return res
@api.model