Skip to content

Commit

Permalink
[MIG] purchase_sale_inter_company: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnmtm committed Sep 6, 2024
1 parent f693466 commit 0c123db
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 39 deletions.
4 changes: 4 additions & 0 deletions purchase_sale_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ Contributors

- Maksym Yankin <[email protected]>

- \`Komit <https://komit-consulting.com>\`:

- Cuong Nguyen Mtm <[email protected]>

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion purchase_sale_inter_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Inter Company Module for Purchase to Sale Order",
"summary": "Intercompany PO/SO rules",
"version": "16.0.1.1.1",
"version": "17.0.1.0.0",
"category": "Purchase Management",
"website": "https://github.com/OCA/multi-company",
"author": "Odoo SA, Akretion, Tecnativa, Odoo Community Association (OCA)",
Expand Down
4 changes: 3 additions & 1 deletion purchase_sale_inter_company/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from markupsafe import Markup

from odoo import _, models


Expand All @@ -28,4 +30,4 @@ def _link_invoice_purchase(self, dest_invoice):
message = _("This vendor bill is related with: {}").format(
",".join([ref.format(o.id, o.name) for o in orders])
)
dest_invoice.message_post(body=message)
dest_invoice.message_post(body=Markup(message))
3 changes: 2 additions & 1 deletion purchase_sale_inter_company/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def button_cancel(self):
for so in sale_orders:
if so.state not in ["draft", "sent", "cancel"]:
raise UserError(_("You can't cancel an order that is %s") % so.state)
sale_orders.action_cancel()
for so in sale_orders:
so.action_cancel()
self.write({"partner_ref": False})
return super().button_cancel()
6 changes: 4 additions & 2 deletions purchase_sale_inter_company/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create(self, vals_list):
or self.env.user
)
sale_lines = []
for purchase_line in lines.filtered(lambda x: x.order_id == order):
for purchase_line in lines.filtered(lambda x, o=order: x.order_id == o):
sale_lines.append(
order._prepare_sale_order_line_data(
purchase_line,
Expand Down Expand Up @@ -102,7 +102,9 @@ def write(self, vals):
{
"order_line": [
(1, line.id, update_vals)
for line in sale_lines.filtered(lambda x: x.order_id == sale)
for line in sale_lines.filtered(
lambda x, s=sale: x.order_id == s
)
]
}
)
Expand Down
2 changes: 2 additions & 0 deletions purchase_sale_inter_company/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
- Pedro M. Baeza
- \`Camptocamp \<<https://www.camptocamp.com>\>\`:
- Maksym Yankin \<<[email protected]>\>
- \`Komit \<<https://komit-consulting.com>\>\`:
- Cuong Nguyen Mtm \<<[email protected]>\>
16 changes: 11 additions & 5 deletions purchase_sale_inter_company/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -464,12 +464,18 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Maksym Yankin &lt;<a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a>&gt;</li>
</ul>
</li>
<li>`Komit &lt;<a class="reference external" href="https://komit-consulting.com">https://komit-consulting.com</a>&gt;`:<ul>
<li>Cuong Nguyen Mtm &lt;<a class="reference external" href="mailto:cuong.nmtm&#64;komit-consulting.com">cuong.nmtm&#64;komit-consulting.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def setUpClass(cls):
# Create purchase order
cls.purchase_company_a = cls._create_purchase_order(cls.partner_company_b)

# Configure pricelist to USD
# Configure pricelist to EUR
cls.env["product.pricelist"].sudo().search([]).write(
{"currency_id": cls.env.ref("base.USD").id}
{"currency_id": cls.env.ref("base.EUR").id}
)

def _approve_po(self):
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_raise_product_access(self):
self._approve_po()

def test_raise_currency(self):
currency = self.env.ref("base.EUR")
currency = self.env.ref("base.USD")
self.purchase_company_a.currency_id = currency
with self.assertRaises(UserError):
self._approve_po()
Expand Down Expand Up @@ -162,6 +162,7 @@ def test_cancel_confirmed_po_so(self):
self.purchase_company_a.with_user(self.user_company_a).button_cancel()

def test_so_change_price(self):
self.company_b.sale_auto_validation = False
sale = self._approve_po()
sale.order_line.price_unit = 10
sale.action_confirm()
Expand All @@ -182,6 +183,7 @@ def test_update_open_sale_order(self):
When the purchase user request extra product, the sale order gets synched if
it's open.
"""
self.company_b.sale_auto_validation = False
purchase = self.purchase_company_a
sale = self._approve_po()
sale.action_confirm()
Expand Down Expand Up @@ -221,3 +223,74 @@ def test_update_open_sale_order(self):
3,
"The quantity should decrease as it was in the purchase order",
)

def test_default_intercompany_sale_user_id(self):
"""
When the intercompany_sale_user_id is not set, the current user that creates the
purchase order is used, this impacts the salesperson value on the sale order.
Following the _compute_user_id method on sale.order model, if there is no
salesperson set, the salesperson will be the user set on the Sale's customer,
or customer's company, or the current user if he is a salesman.
"""
self.company_b.intercompany_sale_user_id = False
self.company_b.sale_auto_validation = False
sale = self._approve_po()
self.assertEqual(sale.create_uid, self.user_company_a)
self.assertNotEqual(sale.user_id, self.user_company_b)
expected_salesperson = (
sale.partner_id.user_id
or sale.partner_id.parent_id.user_id
or (
self.user_company_a
if self.user_company_a.has_group("sales_team.group_sale_manager")
else False
)
)
self.assertNotEqual(sale.user_id, expected_salesperson)

def test_sale_order_line_note_sync(self):
"""
When a purchase order line has a note, it should be copied to the sale order
line.
"""
self.purchase_company_a.order_line = [
(0, 0, {"name": "Test Note", "display_type": "line_note", "product_qty": 0})
]
sale = self._approve_po()
self.assertEqual(
sale.order_line.filtered(lambda x: x.display_type == "line_note").name,
"Test Note",
)

def test_cannot_modify_pol_of_related_so_is_cancel(self):
"""
When the related sale order is cancel, the purchase order lines cannot be
created or modified.
"""
self.company_b.sale_auto_validation = False
sale = self._approve_po()
sale.action_confirm()
purchase_line = self.purchase_company_a.order_line
sale._action_cancel()
with self.assertRaises(UserError):
purchase_line[0].product_qty = 5
with self.assertRaises(UserError):
self.env["purchase.order.line"].create(
{
"order_id": self.purchase_company_a.id,
"product_id": self.service_product_2.id,
"product_qty": 5,
"name": "Test",
}
)
sale.action_draft()
sale.action_confirm()
purchase_line[0].product_qty = 5
self.env["purchase.order.line"].create(
{
"order_id": self.purchase_company_a.id,
"product_id": self.service_product_2.id,
"product_qty": 5,
"name": "Test",
}
)
54 changes: 28 additions & 26 deletions purchase_sale_inter_company/views/res_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@
ref="account_invoice_inter_company.res_config_settings_view_form"
/>
<field name="arch" type="xml">
<xpath
expr="//div[@id='inter_company_invoice_validation']"
position='after'
>
<div class="o_form_label mt8">Purchase/Sale</div>
<div id="inter_company_so_from_po">
<field name="so_from_po" class="oe_inline" />
<label
string="Sale from purchase"
class="o_light_label"
for="so_from_po"
/>
</div>
<div
id="inter_company_settings"
attrs="{'invisible':['|', ('company_id', '=', False), ('so_from_po', '=', False)]}"
>
<label for="intercompany_sale_user_id" class="o_light_label" />
<field
name="intercompany_sale_user_id"
attrs="{'required': [('so_from_po', '=', True)]}"
class="oe_inline"
/>
<br />
<field name="sale_auto_validation" class="oe_inline" />
<label for="sale_auto_validation" class="oe_inline o_light_label" />
<xpath expr="//setting[@id='inter_company_oca']" position='inside'>
<div class="text-decoration-underline mt8 mb8">Purchase / Sale</div>
<div class="content-group">
<div>
<label
string="Sale from purchase"
class="o_light_label mr8"
for="so_from_po"
/>
<field name="so_from_po" class="oe_inline" />
</div>
<div invisible="not company_id or not so_from_po">
<label
for="intercompany_sale_user_id"
class="o_light_label mr8"
/>
<field
name="intercompany_sale_user_id"
required="so_from_po"
class="oe_inline mr8"
/>
<br />
<label
for="sale_auto_validation"
class="oe_inline o_light_label mr8"
/>
<field name="sale_auto_validation" class="oe_inline" />
</div>
</div>
</xpath>
</field>
Expand Down

0 comments on commit 0c123db

Please sign in to comment.