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

16.0 sale product pack price wizard #324

Draft
wants to merge 5 commits into
base: 16.0
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions sale_product_pack_price_wizard/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
==============================
Sale Product Pack Price Wizard
==============================

Adjust pack price from any of its line

Configuration
=============

To configure this module, you need to:

#. Go to ...

Usage
=====

To use this module, you need to:

#. Go to ...


Changelog
=========
2 changes: 2 additions & 0 deletions sale_product_pack_price_wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
22 changes: 22 additions & 0 deletions sale_product_pack_price_wizard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Product Pack Price Wizard",
"description": """
Adjust pack price from any of its line""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Akretion",
"website": "https://github.com/akretion/ak-odoo-incubator",
"depends": [
"sale_management",
"sale_product_pack",
],
"data": [
"security/ir.model.access.csv",
"data/price_data.xml",
"views/sale_order_line_pack_price.xml",
],
"demo": [],
}
7 changes: 7 additions & 0 deletions sale_product_pack_price_wizard/data/price_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record forcecreate="True" id="line_item_price" model="decimal.precision">
<field name="name">Line Item Price</field>
<field name="digits">4</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions sale_product_pack_price_wizard/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order_line
from . import account_move_line
11 changes: 11 additions & 0 deletions sale_product_pack_price_wizard/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Akretion - Raphaël Valyi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

price_unit = fields.Float(
digits="Line Item Price",
)
18 changes: 18 additions & 0 deletions sale_product_pack_price_wizard/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Akretion - Raphaël Valyi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


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

is_pack_line = fields.Boolean(compute="_compute_is_pack_line")

price_unit = fields.Float(
digits="Line Item Price",
)

@api.depends("product_id")
def _compute_is_pack_line(self):
for line in self:
line.is_pack_line = line.product_id.pack_ok or line.pack_parent_line_id
2 changes: 2 additions & 0 deletions sale_product_pack_price_wizard/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sale_order_line_pack_price,access_sale_order_line_pack_price,model_sale_order_line_pack_price,sales_team.group_sale_salesman,1,1,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2023 Akretion
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.model.access" id="sale_order_line_pack_price_access_name"> <!-- TODO acl id -->
<field name="name">sale.order.line.pack.price access name</field> <!-- TODO acl name -->
<field name="model_id" ref="model_sale_order_line_pack_price"/>
<!-- TODO review and adapt -->
<field name="group_id" ref="base.group_user"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2023 Akretion
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="sale_order_line_pack_price_form_view">
<field name="name">sale.order.line.pack.price.form (in sale_product_pack_price_wizard)</field>
<field name="model">sale.order.line.pack.price</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="sale_order_line_id" readonly="1" invisible="1"/>
<field name="pack_price_catalog"/>
<field name="pack_price_edit"/>
<field name="computed_discount"/>
</group>
</sheet>
<footer>
<button string="Appliquer" name="action_set_price" type="object" class="oe_highlight" data-hotkey="q"/>
<button string="Cancel" class="btn btn-secondary" special="cancel" data-hotkey="z"/>
</footer>
</form>
</field>
</record>

<record id="sale_order_line_pack_price_action" model="ir.actions.act_window">
<field name="name">Pack Price</field>
<field name="res_model">sale.order.line.pack.price</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<record id="sale_order_form" model="ir.ui.view">
<field name="name">sale.order.form (in sale_product_pack_price_wizard)</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//tree//field[@name='price_unit']" position="after">
<field name="is_pack_line" invisible="1" />
<button
name="%(sale_order_line_pack_price_action)d"
string="Changer prix"
type="action"
icon="fa-calculator"
attrs="{'invisible': [('is_pack_line', '=', False)]}"
/>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions sale_product_pack_price_wizard/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order_line_pack_price
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError


class SaleOrderLinePackPrice(models.Model):
_name = "sale.order.line.pack.price"
_description = "Sale Order Line Pack Price"
_rec_name = "sale_order_line_id"

def _default_pack_price_edit(self):
order_line = self.env["sale.order.line"].browse(
self.env.context.get("active_id")
)
return self._get_pack_price_catalog(order_line)

def _get_pack_price_catalog(self, order_line):
if (
order_line.pack_parent_line_id.product_id.pack_component_price
== "totalized"
):
raise UserError("Remise interdite pour cet type de pack!")

if order_line.pack_parent_line_id:
order_lines = order_line.pack_parent_line_id.pack_child_line_ids
else:
order_lines = order_line.pack_child_line_ids

total = sum(
line.product_id.list_price * line.product_uom_qty for line in order_lines
)
return total

sale_order_line_id = fields.Many2one(
comodel_name="sale.order.line",
string="Sale order line",
default=lambda self: self.env.context.get("active_id"),
)
currency_id = fields.Many2one(related="sale_order_line_id.currency_id")

pack_price_catalog = fields.Monetary(
string="Prix catalogue du Pack",
compute="_compute_pack_price_catalog",
currency_field="currency_id",
)
pack_price_edit = fields.Monetary(
string="Prix remisé",
currency_field="currency_id",
default=_default_pack_price_edit,
)
computed_discount = fields.Float(
string="Taux de remise", digits=(2, 14), compute="_compute_computed_discount"
)

@api.depends("sale_order_line_id")
def _compute_pack_price_catalog(self):
for wiz in self:
wiz.pack_price_catalog = self._get_pack_price_catalog(
wiz.sale_order_line_id
)

@api.onchange("pack_price_edit")
def _compute_computed_discount(self):
for wiz in self:
if wiz.pack_price_catalog:
wiz.computed_discount = (
100
* (wiz.pack_price_catalog - wiz.pack_price_edit)
/ wiz.pack_price_catalog
)
else:
wiz.computed_discount = 0.0

def action_set_price(self):
for wiz in self:
so = wiz.sale_order_line_id.order_id
pack_line = (
wiz.sale_order_line_id.pack_parent_line_id or wiz.sale_order_line_id
)
for line in so.order_line:
if line.pack_parent_line_id.id == pack_line.id:
line.discount = 0 # wiz.computed_discount
line.price_unit = line.product_id.list_price * (
1 - wiz.computed_discount / 100.0
)
Loading