mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
update
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
|
||||
from . import product
|
||||
from . import procurement
|
||||
from . import warehouse
|
||||
@@ -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
|
||||
13
app_procurement_for_subcontract_service/models/product.py
Normal file
13
app_procurement_for_subcontract_service/models/product.py
Normal 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)
|
||||
52
app_procurement_for_subcontract_service/models/warehouse.py
Normal file
52
app_procurement_for_subcontract_service/models/warehouse.py
Normal 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
|
||||
Reference in New Issue
Block a user