Skip to content

Commit

Permalink
[14.0][IMP] custom_sale_order_type_route: Change create picking funct…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
Tu Nombre committed Oct 3, 2024
1 parent f25578b commit 0021370
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 51 deletions.
22 changes: 20 additions & 2 deletions custom_sale_order_type_route/i18n/custom_sale_order_type_route.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-30 10:42+0000\n"
"PO-Revision-Date: 2024-07-30 10:42+0000\n"
"POT-Creation-Date: 2024-10-03 07:42+0000\n"
"PO-Revision-Date: 2024-10-03 07:42+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -53,6 +53,13 @@ msgstr ""
msgid "Contact"
msgstr ""

#. module: custom_sale_order_type_route
#: code:addons/custom_sale_order_type_route/models/sale_order_type.py:0
#: model_terms:ir.ui.view,arch_db:custom_sale_order_type_route.sot_sale_order_type_form_view
#, python-format
msgid "Contacts"
msgstr ""

#. module: custom_sale_order_type_route
#: model_terms:ir.actions.act_window,help:custom_sale_order_type_route.action_my_route_type_sales
#: model_terms:ir.actions.act_window,help:custom_sale_order_type_route.action_route_type_sales
Expand Down Expand Up @@ -96,6 +103,12 @@ msgstr ""
msgid "Display Name"
msgstr ""

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_partner__distribution_sequence
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_users__distribution_sequence
msgid "Distribution Sequence"
msgstr ""

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_account_payment__id
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_partner__id
Expand Down Expand Up @@ -152,6 +165,11 @@ msgstr ""
msgid "Not Route Type"
msgstr ""

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_sale_order__partner_distribution_sequence
msgid "Partner Distribution Sequence"
msgstr ""

#. module: custom_sale_order_type_route
#: model:ir.model,name:custom_sale_order_type_route.model_account_payment
msgid "Payments"
Expand Down
22 changes: 20 additions & 2 deletions custom_sale_order_type_route/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-30 10:42+0000\n"
"PO-Revision-Date: 2024-07-30 10:42+0000\n"
"POT-Creation-Date: 2024-10-03 07:42+0000\n"
"PO-Revision-Date: 2024-10-03 07:42+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -53,6 +53,13 @@ msgstr "Tipo carga"
msgid "Contact"
msgstr "Contacto"

#. module: custom_sale_order_type_route
#: code:addons/custom_sale_order_type_route/models/sale_order_type.py:0
#: model_terms:ir.ui.view,arch_db:custom_sale_order_type_route.sot_sale_order_type_form_view
#, python-format
msgid "Contacts"
msgstr "Contactos"

#. module: custom_sale_order_type_route
#: model_terms:ir.actions.act_window,help:custom_sale_order_type_route.action_my_route_type_sales
#: model_terms:ir.actions.act_window,help:custom_sale_order_type_route.action_route_type_sales
Expand Down Expand Up @@ -96,6 +103,12 @@ msgstr "Repartidor"
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_partner__distribution_sequence
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_users__distribution_sequence
msgid "Distribution Sequence"
msgstr "Órden de reparto"

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_account_payment__id
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_res_partner__id
Expand Down Expand Up @@ -152,6 +165,11 @@ msgstr "Mis ventas"
msgid "Not Route Type"
msgstr "No es tipo ruta"

#. module: custom_sale_order_type_route
#: model:ir.model.fields,field_description:custom_sale_order_type_route.field_sale_order__partner_distribution_sequence
msgid "Partner Distribution Sequence"
msgstr "Órden de reparto"

#. module: custom_sale_order_type_route
#: model:ir.model,name:custom_sale_order_type_route.model_account_payment
msgid "Payments"
Expand Down
3 changes: 3 additions & 0 deletions custom_sale_order_type_route/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ class ResPartner(models.Model):
string="Special Burden",
default=False,
)
distribution_sequence = fields.Integer(
string="Distribution Sequence",
)
5 changes: 5 additions & 0 deletions custom_sale_order_type_route/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class SaleOrder(models.Model):
string="Special Burden",
default=False,
)
partner_distribution_sequence = fields.Integer(
string="Partner Distribution Sequence",
related="partner_shipping_id.distribution_sequence",
store=True,
)

def _compute_deliverement_menu(self):
for sale in self:
Expand Down
114 changes: 68 additions & 46 deletions custom_sale_order_type_route/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,55 @@ def action_create_burden_picking(self):
if line.order_id.type_id.burden_picking_type not in burden_type:
burden_picking_type = line.order_id.type_id.burden_picking_type
burden_type.append(burden_picking_type)
picking = self.env["stock.picking"].create(
{
"picking_type_id": burden_picking_type.id,
"location_id": burden_picking_type.default_location_src_id.id,
"location_dest_id": burden_picking_type.default_location_dest_id.id,
"custom_date_done": fields.datetime.now(),
"user_id": self.env.user.id,
"company_id": line.company_id.id,
}
)
picking_obj = self.env["stock.picking"]
vals = {
"picking_type_id": burden_picking_type.id,
"location_id": burden_picking_type.default_location_src_id.id,
"location_dest_id": burden_picking_type.default_location_dest_id.id,
"custom_date_done": fields.datetime.now(),
"user_id": self.env.user.id,
"company_id": line.company_id.id,
}
picking = picking_obj.new(vals)
for comp_onchange in picking._onchange_methods[
"picking_type_id",
]:
comp_onchange(picking)
picking = picking._convert_to_write(picking._cache)
picking = picking_obj.create(picking)
lines = []
same_type_lines = self.filtered(
lambda c: c.order_id.type_id.burden_picking_type
== burden_picking_type
)
for same_type_line in same_type_lines:
if same_type_line.order_id.special_burden:
self.env["stock.move.line"].create(
{
"picking_id": picking.id,
"product_id": same_type_line.product_id.id,
"burden_partner_id": (
same_type_line.special_partner_id.id
),
"product_uom_id": (same_type_line.product_id.uom_id.id),
"location_id": picking.location_id.id,
"location_dest_id": picking.location_dest_id.id,
"product_packaging_id": (
same_type_line.product_packaging.id
),
"product_packaging_qty": (
same_type_line.product_packaging_qty
),
}
)
move_line_obj = self.env["stock.move.line"]
vals = {
"picking_id": picking.id,
"product_id": same_type_line.product_id.id,
"burden_partner_id": (same_type_line.special_partner_id.id),
"product_uom_id": (same_type_line.product_id.uom_id.id),
"location_id": picking.location_id.id,
"location_dest_id": picking.location_dest_id.id,
"product_packaging_id": (
same_type_line.product_packaging.id
),
"product_packaging_qty": (
same_type_line.product_packaging_qty
),
}
move_line = move_line_obj.new(vals)
for comp_onchange in move_line._onchange_methods[
"picking_id",
"product_id",
"product_uom_id",
"product_packaging_id",
"product_packaging_qty",
]:
comp_onchange(move_line)
move_line = move_line._convert_to_write(move_line._cache)
move_line = move_line_obj.create(move_line)
if not same_type_line.order_id.special_burden and (
same_type_line not in lines
):
Expand All @@ -96,23 +110,31 @@ def action_create_burden_picking(self):
== (same_type_line.product_packaging)
and not c.order_id.special_burden
)
self.env["stock.move.line"].create(
{
"picking_id": picking.id,
"product_id": same_type_line.product_id.id,
"burden_partner_id": (
same_type_line.special_partner_id.id
),
"product_uom_id": (same_type_line.product_id.uom_id.id),
"location_id": picking.location_id.id,
"location_dest_id": picking.location_dest_id.id,
"product_packaging_id": (
same_type_line.product_packaging.id
),
"product_packaging_qty": sum(
same_product_package.mapped("product_packaging_qty")
),
}
)
move_line_obj = self.env["stock.move.line"]
vals = {
"picking_id": picking.id,
"product_id": same_type_line.product_id.id,
"burden_partner_id": (same_type_line.special_partner_id.id),
"product_uom_id": (same_type_line.product_id.uom_id.id),
"location_id": picking.location_id.id,
"location_dest_id": picking.location_dest_id.id,
"product_packaging_id": (
same_type_line.product_packaging.id
),
"product_packaging_qty": sum(
same_product_package.mapped("product_packaging_qty")
),
}
move_line = move_line_obj.new(vals)
for comp_onchange in move_line._onchange_methods[
"picking_id",
"product_id",
"product_uom_id",
"product_packaging_id",
"product_packaging_qty",
]:
comp_onchange(move_line)
move_line = move_line._convert_to_write(move_line._cache)
move_line = move_line_obj.create(move_line)
for sale_line in same_product_package:
lines.append(sale_line)
21 changes: 20 additions & 1 deletion custom_sale_order_type_route/models/sale_order_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import _, fields, models


class SaleOrderType(models.Model):
Expand All @@ -14,3 +14,22 @@ class SaleOrderType(models.Model):
burden_picking_type = fields.Many2one(
string="Burden Picking Type", comodel_name="stock.picking.type"
)

def action_view_contact(self):
context = self.env.context.copy()
context.update(
{
"default_sale_type": self.id,
}
)
return {
"name": _("Contacts"),
"view_mode": "tree",
"view_id": self.env.ref(
"custom_sale_order_type_route.view_partner_tree_editable"
).id,
"res_model": "res.partner",
"domain": [("sale_type", "=", self.id)],
"type": "ir.actions.act_window",
"context": context,
}
20 changes: 20 additions & 0 deletions custom_sale_order_type_route/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
<field name="vat" position="after">
<field name="special_burden" />
</field>
<field name="sale_type" position="after">
<field name="distribution_sequence" />
</field>
</field>
</record>

<record id="view_partner_tree_editable" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree" />
<field name="mode">primary</field>
<field name="priority">50</field>
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="create">0</attribute>
<attribute name="editable">bottom</attribute>
<attribute name="default_order">distribution_sequence, name</attribute>
</tree>
<field name="display_name" position="before">
<field name="distribution_sequence" />
</field>
</field>
</record>

Expand Down
9 changes: 9 additions & 0 deletions custom_sale_order_type_route/views/sale_order_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
<field name="model">sale.order.type</field>
<field name="inherit_id" ref="sale_order_type.sot_sale_order_type_form_view" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_stat_button"
icon="fa-users"
type="object"
name="action_view_contact"
string="Contacts"
/>
</div>
<field name="incoterm_id" position="after">
<field name="not_route_type" />
<field
Expand Down
15 changes: 15 additions & 0 deletions custom_sale_order_type_route/views/sale_order_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_quotation_tre" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree" />
<field name="arch" type="xml">
<tree position="attributes">
<attribute
name="default_order"
>partner_distribution_sequence, name</attribute>
</tree>
<field name="name" position="before">
<field name="partner_distribution_sequence" optional="hide" />
</field>
</field>
</record>

<record id="view_order_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
Expand Down

0 comments on commit 0021370

Please sign in to comment.