Last active
October 30, 2015 12:58
-
-
Save lepistone/3f4431e616cbfc44154f to your computer and use it in GitHub Desktop.
Odoo 8: what happens when you confirm a Sale Order (pseudocode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is pseudocode. | |
# | |
# I copied and simplified some of the code that gets run when you validate a | |
# Sale Order in Odoo 8. | |
# | |
# More or less, a procurement is created, copying the Route from the order line | |
# if it has been specified. | |
# | |
# Then the procurement is immediately run, and a choice is made on the rule to | |
# use. | |
# sale_stock/sale_stock.py | |
class sale_stock_SO: | |
def _prepare_order_line_procurement(order, line): | |
proc = super() | |
proc.route_ids = line.route_id | |
proc.warehouse_id = order.warehouse_id | |
proc.partner_dest_id = order.partner_shipping_id | |
proc.location_id = order.partner_shipping_id.property_stock_customer | |
# sale/sale.py | |
class sale_SO: | |
def _prepare_order_line_procurement(order, line): | |
proc = Proc() | |
proc.group_id = order.procurement_group_id # (created if empty) | |
def action_ship_create(self): | |
procs = [] | |
for line in self.order_line: | |
if line.procurement_ids: | |
line.procurement_ids.check() | |
else: | |
procs += Proc.create(self.prepare_order_line_procurement) | |
procs.run() | |
# procurement/procurement.py | |
class Proc: | |
def _assign(self): | |
if not self.rule_id: | |
self.rule_id = self._find_suitable_rule() | |
# stock/procurement.py | |
class stock_Proc: | |
def _find_parent_locations(self): | |
return [self.location_id] + self.parent_locations | |
def _find_suitable_rule(self): | |
if not super(): | |
return self.search_suitable_rule(self._find_parent_locations) | |
def _search_suitable_rule(self, proc): | |
Rule = self.env['procurement.rule'] | |
domain = 'location_id in procurement.location_id (and parents)' | |
if proc.warehouse_id: | |
domain += 'warehouse_id = procurement.warehouse_id or false' | |
# 1st attempt | |
Rule.search(domain + 'route_id in procurement.route_ids') | |
# 2nd attempt | |
Rule.search(domain + | |
'route_id in product and product_category.route_ids') | |
# 3rd attempt | |
Rule.search(domain + 'route_id in warehouse.route_ids') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment