Skip to content

Commit

Permalink
[14.0][FIX] l10n_it_delivery_note shipping address
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Feb 26, 2024
1 parent ade0cc6 commit b61fccd
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 15 deletions.
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 @@ def _create_delivery_note(self):
{
"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 @@ def _get_partners(self):
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(
"Multiple partner found for sale order linked to pickings!"
)
partner_id = partner_ids.commercial_partner_id
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
52 changes: 52 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 @@ -9,6 +9,15 @@


class StockDeliveryNote(StockDeliveryNoteCommon):
def setUp(self):
super().setUp()
self.partner_shipping = self.create_partner("Shipping Address")
self.partner_shipping.write(
{
"parent_id": self.recipient.id,
"type": "delivery",
}
)

# ⇒ "Ordine singolo: consegna parziale"
def test_partial_delivering_single_so(self):
Expand Down Expand Up @@ -220,3 +229,46 @@ def test_delivery_action_confirm_without_ref(self):

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

# ⇒ "Ordine singolo: consegna a indirizzo diverso"
def test_partner_shipping_delivering_single_so(self):
use_adv_notes_group_id = self.env.ref(
"l10n_it_delivery_note.use_advanced_delivery_notes"
).id
self.env.user.write({"groups_id": [(3, use_adv_notes_group_id)]})

StockPicking = self.env["stock.picking"]
StockBackorderConfirmationWizard = self.env["stock.backorder.confirmation"]
sales_order = self.create_sales_order(
[
self.large_desk_line, # 1
self.desk_combination_line, # 1
],
)
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

backorder_wiz_id = picking.button_validate()["res_id"]
backorder_wiz = StockBackorderConfirmationWizard.browse(backorder_wiz_id)
backorder_wiz.process()
self.assertTrue(picking.delivery_note_id)
self.assertEqual(picking.delivery_note_id.partner_id, self.recipient)
self.assertEqual(
picking.delivery_note_id.partner_shipping_id, self.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()
self.assertTrue(picking_backorder.delivery_note_id)
self.assertEqual(picking_backorder.delivery_note_id.partner_id, self.recipient)
self.assertEqual(
picking_backorder.delivery_note_id.partner_shipping_id,
self.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.commercial_partner_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.commercial_partner_id.id
if sale_order_id.partner_invoice_id
else self.partner_id.id
),
"partner_shipping_id": self.partner_shipping_id.id,
Expand Down

0 comments on commit b61fccd

Please sign in to comment.