Skip to content

Commit

Permalink
ADD sale_deliver_service_as_goods
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Jan 1, 2025
1 parent f9469c4 commit aa635b6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_deliver_service_as_goods/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions sale_deliver_service_as_goods/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Sale deliver service as goods",
"summary": "Ship goods and set service products as delivered",
"version": "18.0.1.0.0",
"author": "Akretion",
"license": "AGPL-3",
"depends": [
"sale_stock",
],
"exclude": ["sms"],
"data": [
"views/sale.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions sale_deliver_service_as_goods/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale
43 changes: 43 additions & 0 deletions sale_deliver_service_as_goods/models/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odoo import fields, models
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = "sale.order"

# Used to display ui_ship_all_products
available_case = fields.Boolean(compute="_compute_available_case")

def _compute_available_case(self):
for rec in self:
pick = rec.picking_ids and rec.picking_ids[0]
if rec.state == "sale" and (
not pick
or (
len(pick) == 1
and pick.state != "done"
and pick.products_availability_state == "available"
)
):
rec.available_case = True
else:
rec.available_case = False

def ui_ship_all_products_c(self):
for rec in self:
# TODO check combo
pick = rec.picking_ids and rec.picking_ids[0]
if pick:
if pick == "waiting":
pick.action_assign()
try:
pick.with_context(skip_sms=True).button_validate()
except Exception as err:
raise UserError(err) from err
if pick.state != "done":
# breakpoint() # import pdb; pdb.set_trace()
raise UserError("Problème sur le transfert")
for line in rec.order_line.filtered(
lambda s: s.product_id.type == "service"
):
line.qty_delivered = line.product_uom_qty
3 changes: 3 additions & 0 deletions sale_deliver_service_as_goods/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
15 changes: 15 additions & 0 deletions sale_deliver_service_as_goods/views/sale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>

<record id="view_order_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//button[last()]" position="after">
<button name="ui_ship_all_products_c" string="🚚 Livrer" type="object"
invisible="not available_case"
title="Livre directement tous les produits de la vente quand cela est possible" />
</xpath>
</field>
</record>

</odoo>

0 comments on commit aa635b6

Please sign in to comment.