Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] l10n_it_delivery_note shipping address #3989

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion l10n_it_delivery_note/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ITA - Documento di trasporto
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33dc771dcf0ef741591ab0dd1d1d7a84f0a056b2b015567552a1d41b42767429
!! source digest: sha256:9dd153180635bb1f0eb35f9412390b0da595cfb81cf9d3a26bf65f80244c7318
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -202,6 +202,7 @@ Contributors
* `PyTech-SRL <info@pytech.it>`_:
* Alessandro Uffreduzzi <alessandro.uffreduzzi@pytech.it>
* Sebastiano Picchi <sebastiano.picchi@pytech.it>
* Sergio Corato <https://github.com/sergiocorato>

Maintainers
~~~~~~~~~~~
Expand Down
16 changes: 12 additions & 4 deletions l10n_it_delivery_note/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@
{
"company_id": self.company_id.id,
"partner_sender_id": partners[0].id,
"partner_id": self.sale_id.partner_id.id
if self.sale_id
else partners[0].id,
"partner_id": partners[2].id if self.sale_id else partners[0].id,
"partner_shipping_id": partners[1].id,
"type_id": type_id.id,
"date": self.date_done,
Expand Down Expand Up @@ -411,7 +409,17 @@
else partner_id
)

return (src_partner_id, dest_partner_id)
if self.mapped("sale_id"):
partner_ids = self.mapped("sale_id.partner_invoice_id")
if len(partner_ids) > 1:
raise ValueError(

Check warning on line 415 in l10n_it_delivery_note/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/stock_picking.py#L415

Added line #L415 was not covered by tests
"Multiple partner found for sale order linked to pickings!"
)
partner_id = partner_ids[0]
else:
partner_id = dest_partner_id.commercial_partner_id

return (src_partner_id, dest_partner_id, partner_id)

def get_partners(self):
self._check_delivery_note_consistency()
Expand Down
1 change: 1 addition & 0 deletions l10n_it_delivery_note/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
* `PyTech-SRL <info@pytech.it>`_:
* Alessandro Uffreduzzi <alessandro.uffreduzzi@pytech.it>
* Sebastiano Picchi <sebastiano.picchi@pytech.it>
* Sergio Corato <https://github.com/sergiocorato>
4 changes: 3 additions & 1 deletion l10n_it_delivery_note/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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 Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">ITA - Documento di trasporto</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33dc771dcf0ef741591ab0dd1d1d7a84f0a056b2b015567552a1d41b42767429
!! source digest: sha256:9dd153180635bb1f0eb35f9412390b0da595cfb81cf9d3a26bf65f80244c7318
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_delivery_note"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_delivery_note"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><strong>English</strong></p>
Expand Down Expand Up @@ -539,6 +540,7 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
</dd>
</dl>
</li>
<li>Sergio Corato &lt;<a class="reference external" href="https://github.com/sergiocorato">https://github.com/sergiocorato</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
90 changes: 90 additions & 0 deletions l10n_it_delivery_note/tests/test_stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,93 @@ def test_delivery_action_confirm_without_ref(self):

delivery_note_id.partner_ref = "Reference #1234"
delivery_note_id.action_confirm()

def test_partner_shipping_delivering_single_so(self):
# ⇒ "Ordine singolo: consegna a indirizzo diverso"
self._test_partners()
# ⇒ "Ordine singolo: consegna a indirizzo di consegna e fatturazione diversi"
self._test_partners(test_invoice_partner=True)

def _test_partners(self, test_invoice_partner=False):
user = new_test_user(
self.env,
login=f"test_{'invoice' if test_invoice_partner else 'shipping'}",
groups="stock.group_stock_manager,"
"l10n_it_delivery_note.use_advanced_delivery_notes",
)
self.env.user = user
partner_shipping = self.create_partner(
"Shipping Address Mario Rossi", user.company_id
)
partner_shipping.write(
{
"parent_id": self.recipient.id,
"type": "delivery",
}
)
partner_invoicing = self.create_partner("Invoicing Address", user.company_id)
StockPicking = self.env["stock.picking"]
sales_order = self.create_sales_order(
[
self.large_desk_line, # 1
self.desk_combination_line, # 1
],
)
if test_invoice_partner:
sales_order.write(
{
"partner_invoice_id": partner_invoicing.id,
}
)
self.assertEqual(len(sales_order.order_line), 2)
sales_order.action_confirm()
self.assertEqual(len(sales_order.picking_ids), 1)
picking = sales_order.picking_ids
self.assertEqual(len(picking.move_lines), 2)

# deliver only the first product
picking.move_lines[0].quantity_done = 1
res_dict = picking.button_validate()
wizard = Form(
self.env[(res_dict.get("res_model"))]
.with_user(user)
.with_context(res_dict["context"])
).save()
wizard.process()
res_dict = picking.action_delivery_note_create()
wizard = Form(
self.env[(res_dict.get("res_model"))]
.with_user(user)
.with_context(res_dict["context"])
).save()
wizard.confirm()
self.assertTrue(picking.delivery_note_id)
if test_invoice_partner:
self.assertEqual(picking.delivery_note_id.partner_id, partner_invoicing)
else:
self.assertEqual(picking.delivery_note_id.partner_id, self.recipient)
self.assertEqual(picking.delivery_note_id.partner_shipping_id, partner_shipping)
picking_backorder = StockPicking.search([("backorder_id", "=", picking.id)])
self.assertEqual(len(picking_backorder.move_lines), 1)
picking_backorder.move_lines[0].quantity_done = 1
picking_backorder.button_validate()
res_dict = picking_backorder.action_delivery_note_create()
wizard = Form(
self.env[(res_dict.get("res_model"))]
.with_user(user)
.with_context(res_dict["context"])
).save()
wizard.confirm()
self.assertTrue(picking_backorder.delivery_note_id)
if test_invoice_partner:
self.assertEqual(
picking_backorder.delivery_note_id.partner_id, partner_invoicing
)
else:
self.assertEqual(
picking_backorder.delivery_note_id.partner_id, self.recipient
)
self.assertEqual(
picking_backorder.delivery_note_id.partner_shipping_id,
partner_shipping,
)
8 changes: 6 additions & 2 deletions l10n_it_delivery_note/wizard/delivery_note_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def _domain_type_id(self):
partner_id = fields.Many2one(
"res.partner", string="Recipient", compute="_compute_fields"
)
partner_shipping_id = fields.Many2one("res.partner", string="Shipping address")
partner_shipping_id = fields.Many2one(
"res.partner", string="Shipping address", compute="_compute_fields"
)

date = fields.Date(string="Date")
type_id = fields.Many2one(
Expand Down Expand Up @@ -80,6 +82,7 @@ def _compute_fields(self):
self.error_message = False
self.partner_sender_id = False
self.partner_id = False
self.partner_shipping_id = False
self.check_compliance(self.selected_picking_ids)

except ValidationError:
Expand All @@ -98,7 +101,8 @@ def _compute_fields(self):
self.warning_message = self._get_warning_message()
partners = self.selected_picking_ids.get_partners()
self.partner_sender_id = partners[0]
self.partner_id = partners[1]
self.partner_shipping_id = partners[1]
self.partner_id = partners[2]

def confirm(self):
raise NotImplementedError(
Expand Down
14 changes: 7 additions & 7 deletions l10n_it_delivery_note/wizard/delivery_note_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def _default_type(self):
[("code", "=", "outgoing")], limit=1
)

partner_shipping_id = fields.Many2one("res.partner", required=True)

date = fields.Date(default=_default_date)
type_id = fields.Many2one(
"stock.delivery.note.type", default=_default_type, required=True
Expand Down Expand Up @@ -67,9 +65,11 @@ def _onchange_partner(self):
self.check_compliance(self.selected_picking_ids)
self.update(
{
"partner_shipping_id": self.partner_id,
"partner_id": self.selected_picking_ids.mapped("sale_id.partner_id")
if self.selected_picking_ids.mapped("sale_id.partner_id")
"partner_shipping_id": self.partner_shipping_id,
"partner_id": self.selected_picking_ids.mapped(
"sale_id.partner_invoice_id"
)
if self.selected_picking_ids.mapped("sale_id.partner_invoice_id")
else self.partner_id,
}
)
Expand All @@ -82,8 +82,8 @@ def _prepare_delivery_note_vals(self, sale_order_id):
),
"partner_sender_id": self.partner_sender_id.id,
"partner_id": (
self.selected_picking_ids.mapped("sale_id.partner_id").id
if self.selected_picking_ids.mapped("sale_id.partner_id").id
sale_order_id.partner_invoice_id.id
if sale_order_id.partner_invoice_id
else self.partner_id.id
),
"partner_shipping_id": self.partner_shipping_id.id,
Expand Down
Loading