forked from OCA/multi-company
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'refs/pull/309/head' of github.com:OCA/multi-company int…
…o merge-branch-2872-SSCM-47-e3c18199
- Loading branch information
Showing
14 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_intercompany |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2021 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Stock Intercompany Delivery-Reception", | ||
"Summary": "Module that adds possibility for intercompany Delivery-Reception", | ||
"version": "14.0.1.1.1", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/multi-company", | ||
"category": "Warehouse Management", | ||
"depends": ["stock"], | ||
"installable": True, | ||
"license": "AGPL-3", | ||
"data": [ | ||
"views/res_config_settings.xml", | ||
], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import res_company | ||
from . import res_config_settings | ||
from . import stock_picking |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
intercompany_in_type_id = fields.Many2one( | ||
"stock.picking.type", string="Intercompany operation type" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
intercompany_in_type_id = fields.Many2one( | ||
related="company_id.intercompany_in_type_id", readonly=False | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from odoo import models | ||
|
||
|
||
class StockPicking(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
def _create_counterpart_picking(self): | ||
companies = self.env["res.company"].sudo().search([]) | ||
partners = {cp.partner_id: cp for cp in companies} | ||
if self.partner_id in partners: | ||
company = partners[self.partner_id] | ||
warehouse = False | ||
if company.intercompany_in_type_id.warehouse_id: | ||
warehouse = company.intercompany_in_type_id.warehouse_id | ||
else: | ||
warehouse = ( | ||
self.env["stock.warehouse"] | ||
.sudo() | ||
.search([("company_id", "=", company.id)], limit=1) | ||
) | ||
vals = { | ||
"partner_id": self.env.user.company_id.partner_id.id, | ||
"company_id": company.id, | ||
"picking_type_id": company.intercompany_in_type_id.id | ||
or warehouse.in_type_id.id, | ||
"state": "draft", | ||
"location_id": self.env.ref("stock.stock_location_suppliers").id, | ||
"location_dest_id": warehouse.lot_stock_id.id, | ||
} | ||
new_picking_vals = self.sudo().copy_data(default=vals) | ||
picking = self.env["stock.picking"].sudo().create(new_picking_vals) | ||
picking.action_confirm() | ||
return picking | ||
|
||
# override of method from stock module | ||
def _action_done(self): | ||
counterparts = [] | ||
for picking in self: | ||
if picking.location_dest_id.usage == "customer": | ||
counterpart = picking._create_counterpart_picking() | ||
counterparts.append((picking, counterpart)) | ||
res = super(StockPicking, self)._action_done() | ||
for picking, counterpart in counterparts: | ||
picking._finalize_counterpart_picking(counterpart) | ||
return res | ||
|
||
def _finalize_counterpart_picking(self, counterpart_picking): | ||
"""hook to finalize required steps on the counterpart picking after the initial | ||
outgoing picking is done""" | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* For picking destination company | ||
* Go to Inventory > Settings | ||
* Under 'Operations' set: | ||
|
||
* Intercompany operation type [type incoming] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* Anna Janiszewska <[email protected]> | ||
* Alexandre Fayolle <[email protected]> | ||
* Yannick Vaucher <[email protected]> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This module allows to create counterpart transfers between companies defined in | ||
multi-company configuration. | ||
|
||
For each company 'intercompany operation type' field must be set. Based on | ||
this, when a picking from company A to company B is processed, a new incoming | ||
picking in company B is created, using the picking type defined in the settings | ||
of that company. | ||
|
||
Caution: | ||
|
||
currently, lots and packages are not handled. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_intercompany_picking |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Copyright 2021 Camptocamp | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestIntercompanyDelivery(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.user_demo = self.env.ref("base.user_demo") | ||
company_obj = self.env["res.company"] | ||
# Create 2 companies and configure intercompany picking type param on them | ||
self.company1 = company_obj.create({"name": "Company A"}) | ||
self.company2 = company_obj.create({"name": "Company B"}) | ||
self.picking_type_1 = ( | ||
self.env["stock.picking.type"] | ||
.sudo() | ||
.search( | ||
[ | ||
("company_id", "=", self.company1.id), | ||
("name", "=", "Delivery Orders"), | ||
], | ||
limit=1, | ||
) | ||
) | ||
self.picking_type_2 = ( | ||
self.env["stock.picking.type"] | ||
.sudo() | ||
.search( | ||
[("company_id", "=", self.company2.id), ("name", "=", "Receipts")], | ||
limit=1, | ||
) | ||
) | ||
|
||
self.company1.intercompany_in_type_id = self.picking_type_1.id | ||
self.company2.intercompany_in_type_id = self.picking_type_2.id | ||
# assign both companies to current user | ||
self.user_demo.write( | ||
{ | ||
"company_id": self.company1.id, | ||
"company_ids": [(4, self.company1.id), (4, self.company2.id)], | ||
} | ||
) | ||
# create storable product | ||
self.product1 = self.env["product.product"].create( | ||
{ | ||
"name": "Product A", | ||
"type": "product", | ||
"categ_id": self.env.ref("product.product_category_all").id, | ||
"qty_available": 100, | ||
} | ||
) | ||
self.stock_location = ( | ||
self.env["stock.location"] | ||
.sudo() | ||
.search([("name", "=", "Stock"), ("company_id", "=", self.company1.id)]) | ||
) | ||
self.uom_unit = self.env.ref("uom.product_uom_unit") | ||
|
||
def test_picking_creation(self): | ||
picking = ( | ||
self.env["stock.picking"] | ||
.with_context(default_company_id=self.company1.id) | ||
.with_user(self.user_demo) | ||
.create( | ||
{ | ||
"partner_id": self.company2.partner_id.id, | ||
"location_id": self.stock_location.id, | ||
"location_dest_id": self.env.ref( | ||
"stock.stock_location_suppliers" | ||
).id, | ||
"picking_type_id": self.company1.intercompany_in_type_id.id, | ||
} | ||
) | ||
) | ||
self.env["stock.move.line"].create( | ||
{ | ||
"location_id": self.stock_location.id, | ||
"location_dest_id": self.env.ref("stock.stock_location_suppliers").id, | ||
"product_id": self.product1.id, | ||
"product_uom_id": self.uom_unit.id, | ||
"qty_done": 1.0, | ||
"picking_id": picking.id, | ||
} | ||
) | ||
picking.action_confirm() | ||
picking.button_validate() | ||
|
||
counterpart_pickings = ( | ||
self.env["stock.picking"] | ||
.with_context(default_company_id=self.company2.id) | ||
.with_user(self.user_demo) | ||
.sudo() | ||
.search_count( | ||
[("picking_type_id", "=", self.company1.intercompany_in_type_id.id)] | ||
) | ||
) | ||
|
||
self.assertEqual(counterpart_pickings, 1) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="intercompany_res_config_settings_view_form" model="ir.ui.view"> | ||
<field name="name">intercompany.res.config.settings.view.form</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="stock.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div[@name='operations_setting_container']" position="inside"> | ||
<div | ||
class="col-12 col-lg-6 o_setting_box" | ||
id="intercompany_delivery_sbox" | ||
> | ||
<div class="o_setting_right_pane"> | ||
<label for="intercompany_in_type_id" /> | ||
<span | ||
class="fa fa-lg fa-building-o" | ||
title="Values set here are company-specific." | ||
groups="base.group_multi_company" | ||
/> | ||
<div class="content-group"> | ||
<field name="intercompany_in_type_id" /> | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |