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

[15.0][IMP] delivery_purchase: FWPs changes from 14.0 #742

Merged
merged 4 commits into from
Dec 15, 2023
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
4 changes: 3 additions & 1 deletion delivery_purchase/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Delivery costs in purchases
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e5699ff44ca02792b5261b3120754a8ce6f4ff0e4604f505cc4fb74edbde01cb
!! source digest: sha256:aafa8b7f80448edb2658ef3e16a478bccc54a99435bf9f45058c5ffd4c875fa0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down Expand Up @@ -55,8 +55,10 @@ To use this module, you need to:
#. If necessary, you can change the carrier in the 'Receipt'. When
it is validated, the 'shipping cost' of the receipt will be
calculated according to that new selected Carrier.
#. It is possible to change the shipping cost in picking.
#. The shipping cost will appear in an internal note created
automatically when the 'Receipt' is validated.
#. A purchase order line will have been created for the cost of picking.

Bug Tracker
===========
Expand Down
2 changes: 1 addition & 1 deletion delivery_purchase/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["purchase", "delivery"],
"data": ["views/purchase_order_view.xml"],
"data": ["views/purchase_order_view.xml", "views/stock_picking_view.xml"],
}
42 changes: 42 additions & 0 deletions delivery_purchase/i18n/delivery_purchase.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-31 09:59+0000\n"
"PO-Revision-Date: 2023-10-31 09:59+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -23,6 +25,14 @@ msgstr ""
msgid "Delivery Price"
msgstr ""

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking__display_name
msgid "Display Name"
msgstr ""

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/delivery_carrier.py:0
#, python-format
Expand All @@ -35,11 +45,43 @@ msgstr ""
msgid "Error: this delivery method is not available for this address."
msgstr ""

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/purchase_order.py:0
#, python-format
msgid "Free Shipping"
msgstr ""

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier__id
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order__id
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__id
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking__id
msgid "ID"
msgstr ""

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__is_delivery
msgid "Is a Delivery"
msgstr ""

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking____last_update
msgid "Last Modified on"
msgstr ""

#. module: delivery_purchase
#: model:ir.model,name:delivery_purchase.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: delivery_purchase
#: model:ir.model,name:delivery_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/stock_picking.py:0
#, python-format
Expand Down
40 changes: 40 additions & 0 deletions delivery_purchase/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ msgstr "Método de entrega"
msgid "Delivery Price"
msgstr "Precio de entrega"

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__display_name
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking__display_name
msgid "Display Name"
msgstr "Nombre a mostrar"

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/delivery_carrier.py:0
#, python-format
Expand All @@ -39,11 +47,43 @@ msgstr "Error: no hay cuadrícula coincidente."
msgid "Error: this delivery method is not available for this address."
msgstr "Error: este método de envío no está disponible para esta dirección."

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/purchase_order.py:0
#, python-format
msgid "Free Shipping"
msgstr "Envío gratis"

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier__id
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order__id
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__id
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking__id
msgid "ID"
msgstr "ID"

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line__is_delivery
msgid "Is a Delivery"
msgstr "Es un envío"

#. module: delivery_purchase
#: model:ir.model.fields,field_description:delivery_purchase.field_delivery_carrier____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_purchase_order_line____last_update
#: model:ir.model.fields,field_description:delivery_purchase.field_stock_picking____last_update
msgid "Last Modified on"
msgstr "Última modificación el"

#. module: delivery_purchase
#: model:ir.model,name:delivery_purchase.model_purchase_order
msgid "Purchase Order"
msgstr "Orden de compra"

#. module: delivery_purchase
#: model:ir.model,name:delivery_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Línea de pedido de compra"

#. module: delivery_purchase
#: code:addons/delivery_purchase/models/stock_picking.py:0
#, python-format
Expand Down
68 changes: 62 additions & 6 deletions delivery_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2016 Tecnativa - Pedro M. Baeza
# Copyright 2023 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.tools.float_utils import float_is_zero


class PurchaseOrder(models.Model):
Expand All @@ -12,21 +14,75 @@
comodel_name="delivery.carrier",
string="Delivery Method",
)
delivery_price = fields.Float()
delivery_price = fields.Float(
compute="_compute_delivery_price", store=True, readonly=False
)

@api.onchange("partner_id")
def onchange_partner_id_delivery_purchase(self):
if self.partner_id.property_delivery_carrier_id:
self.carrier_id = self.partner_id.property_delivery_carrier_id.id

@api.onchange("order_line", "amount_total", "carrier_id")
def get_delivery_cost(self):
if self.carrier_id:
self.delivery_price = self.carrier_id.purchase_rate_shipment(self)["price"]
@api.depends("order_line", "order_line.is_delivery", "amount_total", "carrier_id")
def _compute_delivery_price(self):
for item in self.filtered(lambda x: x.carrier_id):
delivery_lines = item.order_line.filtered(lambda x: x.is_delivery)
if delivery_lines:
item.delivery_price = sum(delivery_lines.mapped("price_unit"))
else:
item.delivery_price = item.carrier_id.purchase_rate_shipment(self)[
"price"
]

@api.model
def _prepare_picking(self):
res = super()._prepare_picking()
if self.carrier_id:
res["carrier_id"] = self.carrier_id.id
res["carrier_price"] = self.delivery_price
return res

def _create_delivery_line(self, carrier, price_unit):
pol_model = self.env["purchase.order.line"]
line = pol_model.new(
{
"order_id": self.id,
"product_qty": 1,
"product_id": carrier.product_id.id,
"is_delivery": True,
}
)
line.onchange_product_id()
values = line._convert_to_write(line._cache)
# Override misc info: price_unit, name and sequence
values.update(price_unit=price_unit)
if carrier.free_over and self.currency_id.is_zero(price_unit):
values["name"] += "\n" + _("Free Shipping")

Check warning on line 60 in delivery_purchase/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_purchase/models/purchase_order.py#L60

Added line #L60 was not covered by tests
if self.order_line:
values.update(sequence=self.order_line[-1].sequence + 1)
return pol_model.sudo().create(values)


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

is_delivery = fields.Boolean(string="Is a Delivery", default=False)

@api.depends("is_delivery")
def _compute_qty_invoiced(self):
"""Overwrite and set qty_to_invoice to 0 for delivery lines if all lines
have nothing to invoice."""
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
res = super()._compute_qty_invoiced()
for item in self.filtered(lambda x: x.is_delivery):
order_lines = item.order_id.order_line.filtered(
lambda x: not x.is_delivery and not x.display_type
)
if all(
float_is_zero(line.qty_to_invoice, precision_digits=precision)
for line in order_lines
):
item.qty_to_invoice = 0
return res
21 changes: 10 additions & 11 deletions delivery_purchase/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ def purchase_send_to_shipper(self):

def _add_delivery_cost_to_po(self):
self.ensure_one()
if (
self.purchase_id
and self.carrier_id.invoice_policy == "real"
and self.carrier_price
):
carrier_price = self.carrier_price * (
1.0 + (float(self.carrier_id.margin) / 100.0)
)
self.purchase_id.write(
{"carrier_id": self.carrier_id, "delivery_price": carrier_price}
)
if self.purchase_id and self.carrier_price:
carrier_price = self.carrier_price
# Re-set carrier price
if self.carrier_id.invoice_policy == "real":
carrier_price = self.carrier_price * (
1.0 + (float(self.carrier_id.margin) / 100.0)
)
# Create delivery line allways
self.purchase_id._create_delivery_line(self.carrier_id, carrier_price)
self.purchase_id.write({"carrier_id": self.carrier_id})
2 changes: 2 additions & 0 deletions delivery_purchase/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ To use this module, you need to:
#. If necessary, you can change the carrier in the 'Receipt'. When
it is validated, the 'shipping cost' of the receipt will be
calculated according to that new selected Carrier.
#. It is possible to change the shipping cost in picking.
#. The shipping cost will appear in an internal note created
automatically when the 'Receipt' is validated.
#. A purchase order line will have been created for the cost of picking.
4 changes: 3 additions & 1 deletion delivery_purchase/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Delivery costs in purchases</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e5699ff44ca02792b5261b3120754a8ce6f4ff0e4604f505cc4fb74edbde01cb
!! source digest: sha256:aafa8b7f80448edb2658ef3e16a478bccc54a99435bf9f45058c5ffd4c875fa0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/delivery-carrier/tree/15.0/delivery_purchase"><img alt="OCA/delivery-carrier" src="https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/delivery-carrier-15-0/delivery-carrier-15-0-delivery_purchase"><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/delivery-carrier&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to use delivery methods defined in <em>delivery</em> module to
Expand Down Expand Up @@ -402,8 +402,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>If necessary, you can change the carrier in the ‘Receipt’. When
it is validated, the ‘shipping cost’ of the receipt will be
calculated according to that new selected Carrier.</li>
<li>It is possible to change the shipping cost in picking.</li>
<li>The shipping cost will appear in an internal note created
automatically when the ‘Receipt’ is validated.</li>
<li>A purchase order line will have been created for the cost of picking.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
Expand Down
Loading
Loading