This commit is contained in:
ivan deng
2018-07-21 01:29:32 +08:00
parent 53fb04ee26
commit e0b747e9e1
36 changed files with 358 additions and 330 deletions

View File

@@ -0,0 +1,4 @@
from . import product
from . import procurement
from . import warehouse

View File

@@ -0,0 +1,26 @@
# # Author: Damien Crier
# # Copyright 2017 Camptocamp SA
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
#
from odoo import api, models
class ProcurementGroup(models.Model):
_inherit = "procurement.group"
@api.model
def _is_subcontracted_service(self, product_id):
return (product_id.type == 'service' and
product_id.property_subcontracted_service or
False)
@api.model
def _get_rule(self, product_id, location_id, values):
res = super()._get_rule(product_id, location_id, values)
if not res:
if self._is_subcontracted_service(product_id):
rule_id = location_id.get_warehouse().\
subcontracting_service_proc_rule_id
if rule_id:
return rule_id
return res

View File

@@ -0,0 +1,13 @@
# Author: Damien Crier
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
property_subcontracted_service = fields.Boolean(
string="Subcontracted Service",
company_dependent=True)

View File

@@ -0,0 +1,52 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
class StockWarehouse(models.Model):
_inherit = 'stock.warehouse'
subcontracting_service_proc_rule_id = fields.Many2one(
comodel_name='procurement.rule',
string="Subcontracting Service Procurement Rule"
)
def _get_buy_route(self):
return self.env.ref('purchase.route_warehouse0_buy',
raise_if_not_found=False).id
@api.multi
def _get_vals_for_proc_rule_subcontracting(self):
self.ensure_one()
picking_type = self.env['stock.picking.type'].search(
[('code', '=', 'incoming'),
('warehouse_id', '=', self.id)
],
limit=1
)
return {'name': _('%s: Subcontracting service rule' % self.name),
'company_id': self.company_id.id,
'action': 'buy',
'picking_type_id': picking_type.id,
'location_id': picking_type.default_location_dest_id.id,
'route_id': self._get_buy_route(),
}
@api.multi
def _set_subcontracting_service_proc_rule(self):
for rec in self:
if rec.subcontracting_service_proc_rule_id:
continue
vals = rec._get_vals_for_proc_rule_subcontracting()
rule = self.env['procurement.rule'].create(vals)
rec.subcontracting_service_proc_rule_id = rule.id
return True
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
res = super(StockWarehouse, self).create(vals)
res._set_subcontracting_service_proc_rule()
return res