Browse Source
Merge pull request #145 from beescoop/12.0-mig-compute_purchase_order
Merge pull request #145 from beescoop/12.0-mig-compute_purchase_order
[12.0] [MIG] compute_purchase_orderpull/149/head
Rémy Taymans
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1168 additions and 0 deletions
-
58purchase_order_generator/README.rst
-
1purchase_order_generator/__init__.py
-
19purchase_order_generator/__manifest__.py
-
4purchase_order_generator/models/__init__.py
-
31purchase_order_generator/models/product_template.py
-
45purchase_order_generator/models/purchase_order.py
-
166purchase_order_generator/models/purchase_order_generator.py
-
181purchase_order_generator/models/purchase_order_generator_line.py
-
2purchase_order_generator/readme/CONTRIBUTORS.rst
-
1purchase_order_generator/readme/DESCRIPTION.rst
-
0purchase_order_generator/readme/USAGE.rst
-
11purchase_order_generator/security/ir.model.access.csv
-
415purchase_order_generator/static/description/index.html
-
1purchase_order_generator/tests/__init__.py
-
84purchase_order_generator/tests/test_pog.py
-
23purchase_order_generator/views/product_template.xml
-
13purchase_order_generator/views/purchase_order.xml
-
113purchase_order_generator/views/purchase_order_generator.xml
@ -0,0 +1,58 @@ |
|||||
|
======================== |
||||
|
Purchase Order Generator |
||||
|
======================== |
||||
|
|
||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
|
||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
||||
|
:target: https://odoo-community.org/page/development-status |
||||
|
:alt: Beta |
||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
.. |badge3| image:: https://img.shields.io/badge/github-beescoop%2Fobeesdoo-lightgray.png?logo=github |
||||
|
:target: https://github.com/beescoop/obeesdoo/tree/12.0/purchase_order_generator |
||||
|
:alt: beescoop/obeesdoo |
||||
|
|
||||
|
|badge1| |badge2| |badge3| |
||||
|
|
||||
|
Generate purchase order from a product selection. |
||||
|
|
||||
|
**Table of contents** |
||||
|
|
||||
|
.. contents:: |
||||
|
:local: |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/beescoop/obeesdoo/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
`feedback <https://github.com/beescoop/obeesdoo/issues/new?body=module:%20purchase_order_generator%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Do not contact contributors directly about support or help with technical issues. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Authors |
||||
|
~~~~~~~ |
||||
|
|
||||
|
* Coop IT Easy SCRLfs |
||||
|
|
||||
|
Contributors |
||||
|
~~~~~~~~~~~~ |
||||
|
|
||||
|
* Robin Keunen <robin@coopiteasy.be> |
||||
|
* Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
|
||||
|
Maintainers |
||||
|
~~~~~~~~~~~ |
||||
|
|
||||
|
This module is part of the `beescoop/obeesdoo <https://github.com/beescoop/obeesdoo/tree/12.0/purchase_order_generator>`_ project on GitHub. |
||||
|
|
||||
|
You are welcome to contribute. |
@ -0,0 +1 @@ |
|||||
|
from . import models |
@ -0,0 +1,19 @@ |
|||||
|
# Copyright 2020 Coop IT Easy SCRL fs |
||||
|
# Robin Keunen <robin@coopiteasy.be> |
||||
|
# Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
{ |
||||
|
"name": "Purchase Order Generator", |
||||
|
"version": "12.0.1.0.0", |
||||
|
"category": "Purchase Order", |
||||
|
"summary": "Generate purchase order from a product selection", |
||||
|
"author": "Coop IT Easy SCRLfs", |
||||
|
"website": "https://github.com/beescoop/obeesdoo/", |
||||
|
"license": "AGPL-3", |
||||
|
"depends": ["purchase", "beesdoo_stock_coverage"], |
||||
|
"data": [ |
||||
|
"security/ir.model.access.csv", |
||||
|
"views/purchase_order_generator.xml", |
||||
|
"views/purchase_order.xml", |
||||
|
], |
||||
|
} |
@ -0,0 +1,4 @@ |
|||||
|
from . import purchase_order |
||||
|
from . import purchase_order_generator |
||||
|
from . import purchase_order_generator_line |
||||
|
from . import product_template |
@ -0,0 +1,31 @@ |
|||||
|
# Copyright 2020 Coop IT Easy SCRL fs |
||||
|
# Robin Keunen <robin@coopiteasy.be> |
||||
|
# Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import models, fields, api |
||||
|
|
||||
|
|
||||
|
class ProductTemplate(models.Model): |
||||
|
_inherit = "product.template" |
||||
|
|
||||
|
main_supplier_id = fields.Many2one( |
||||
|
"res.partner", compute="_compute_main_supplier_id", store=True |
||||
|
) |
||||
|
|
||||
|
def _get_sorted_supplierinfo(self): |
||||
|
return self.seller_ids.sorted( |
||||
|
key=lambda seller: seller.date_start, reverse=True |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("seller_ids", "seller_ids.date_start") |
||||
|
def _compute_main_supplier_id(self): |
||||
|
for pt in self: |
||||
|
sellers_ids = pt.seller_ids.sorted( |
||||
|
key=lambda seller: seller.date_start, reverse=True |
||||
|
) |
||||
|
if sellers_ids: |
||||
|
pt.main_supplier_id = sellers_ids[0].name |
||||
|
else: |
||||
|
pt.main_supplier_id = False |
@ -0,0 +1,45 @@ |
|||||
|
# Copyright 2020 Coop IT Easy SCRL fs |
||||
|
# Robin Keunen <robin@coopiteasy.be> |
||||
|
# Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
from odoo import models, fields, api, SUPERUSER_ID |
||||
|
|
||||
|
|
||||
|
class PurchaseOrder(models.Model): |
||||
|
_inherit = "purchase.order" |
||||
|
|
||||
|
original_cpo_id = fields.Many2one( |
||||
|
"purchase.order.generator", |
||||
|
string="Original POG", |
||||
|
help="POG used to generate this Purchase Order", |
||||
|
) |
||||
|
|
||||
|
|
||||
|
class PurchaseOrderLine(models.Model): |
||||
|
_inherit = "purchase.order.line" |
||||
|
|
||||
|
@api.multi |
||||
|
def compute_taxes_id(self): |
||||
|
for pol in self: |
||||
|
if self.env.uid == SUPERUSER_ID: |
||||
|
company_id = self.env.user.company_id.id |
||||
|
else: |
||||
|
company_id = self.company_id.id |
||||
|
|
||||
|
fpos_id = ( |
||||
|
self.env["account.fiscal.position"] |
||||
|
.with_context(company_id=company_id) |
||||
|
.get_fiscal_position(pol.partner_id.id) |
||||
|
) |
||||
|
fpos = self.env["account.fiscal.position"].browse(fpos_id) |
||||
|
pol.order_id.fiscal_position_id = fpos |
||||
|
|
||||
|
taxes = self.product_id.supplier_taxes_id |
||||
|
taxes_id = fpos.map_tax(taxes) if fpos else taxes |
||||
|
|
||||
|
if taxes_id: |
||||
|
taxes_id = taxes_id.filtered( |
||||
|
lambda t: t.company_id.id == company_id |
||||
|
) |
||||
|
|
||||
|
pol.taxes_id = taxes_id |
@ -0,0 +1,166 @@ |
|||||
|
# Copyright 2020 Coop IT Easy SCRL fs |
||||
|
# Robin Keunen <robin@coopiteasy.be> |
||||
|
# Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import models, fields, api, _ |
||||
|
from odoo.exceptions import ValidationError |
||||
|
|
||||
|
|
||||
|
class PurchaseOrderGenerator(models.Model): |
||||
|
_description = "Purchase Order Generator" |
||||
|
_name = "purchase.order.generator" |
||||
|
_order = "id desc" |
||||
|
|
||||
|
name = fields.Char(string="POG Reference", default=_("New")) |
||||
|
order_date = fields.Datetime( |
||||
|
string="Purchase Order Date", |
||||
|
default=fields.Datetime.now, |
||||
|
help="Date at which the Quotation should be validated and " |
||||
|
"converted into a purchase order.", |
||||
|
) |
||||
|
date_planned = fields.Datetime( |
||||
|
string="Date Planned", |
||||
|
default=fields.Datetime.now, |
||||
|
) |
||||
|
supplier_id = fields.Many2one( |
||||
|
comodel_name="res.partner", |
||||
|
string="Supplier", |
||||
|
readonly=True, |
||||
|
help="Supplier of the purchase order.", |
||||
|
) |
||||
|
pog_line_ids = fields.One2many( |
||||
|
comodel_name="purchase.order.generator.line", |
||||
|
inverse_name="cpo_id", |
||||
|
string="Order Lines", |
||||
|
) |
||||
|
total_amount = fields.Float( |
||||
|
string="Total Amount (w/o VAT)", compute="compute_pog_total" |
||||
|
) |
||||
|
generated_purchase_order_ids = fields.One2many( |
||||
|
comodel_name="purchase.order", |
||||
|
inverse_name="original_cpo_id", |
||||
|
string="Generated Purchase Orders", |
||||
|
) |
||||
|
generated_po_count = fields.Integer( |
||||
|
string="Generated Purchase Order count", |
||||
|
compute="_compute_generated_po_count", |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("pog_line_ids", "pog_line_ids.purchase_quantity") |
||||
|
def compute_pog_total(self): |
||||
|
for cpo in self: |
||||
|
total_amount = sum(cpol.subtotal for cpol in cpo.pog_line_ids) |
||||
|
cpo.total_amount = total_amount |
||||
|
|
||||
|
@api.model |
||||
|
def _get_selected_supplier(self): |
||||
|
product_ids = self.env.context.get("active_ids", []) |
||||
|
products = self.env["product.template"].browse(product_ids) |
||||
|
suppliers = products.mapped("main_supplier_id") |
||||
|
|
||||
|
if not suppliers: |
||||
|
raise ValidationError("No supplier is set for selected articles.") |
||||
|
elif len(suppliers) == 1: |
||||
|
return suppliers |
||||
|
else: |
||||
|
raise ValidationError( |
||||
|
"You must select article from a single supplier." |
||||
|
) |
||||
|
|
||||
|
@api.model |
||||
|
def generate_cpo(self): |
||||
|
order_line_obj = self.env["purchase.order.generator.line"] |
||||
|
product_ids = self.env.context.get("active_ids", []) |
||||
|
|
||||
|
supplier = self._get_selected_supplier() |
||||
|
name = "POG {} {}".format(supplier.name, fields.Date.today()) |
||||
|
cpo = self.create({"name": name, "supplier_id": supplier.id}) |
||||
|
|
||||
|
for product_id in product_ids: |
||||
|
supplierinfo = self.env["product.supplierinfo"].search( |
||||
|
[ |
||||
|
("product_tmpl_id", "=", product_id), |
||||
|
("name", "=", supplier.id), |
||||
|
] |
||||
|
) |
||||
|
min_qty = supplierinfo.min_qty if supplierinfo else 0 |
||||
|
order_line_obj.create( |
||||
|
{ |
||||
|
"cpo_id": cpo.id, |
||||
|
"product_template_id": product_id, |
||||
|
"purchase_quantity": min_qty, |
||||
|
} |
||||
|
) |
||||
|
action = { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"res_model": "purchase.order.generator", |
||||
|
"res_id": cpo.id, |
||||
|
"view_type": "form", |
||||
|
"view_mode": "form,tree", |
||||
|
"target": "current", |
||||
|
} |
||||
|
return action |
||||
|
|
||||
|
@api.multi |
||||
|
def create_purchase_order(self): |
||||
|
self.ensure_one() |
||||
|
|
||||
|
if sum(self.pog_line_ids.mapped("purchase_quantity")) == 0: |
||||
|
raise ValidationError( |
||||
|
"You need at least a product to generate " "a Purchase Order" |
||||
|
) |
||||
|
|
||||
|
purchase_order = self.env["purchase.order"].create( |
||||
|
{ |
||||
|
"date_order": self.order_date, |
||||
|
"partner_id": self.supplier_id.id, |
||||
|
"date_planned": self.date_planned, |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
for cpo_line in self.pog_line_ids: |
||||
|
if cpo_line.purchase_quantity > 0: |
||||
|
pol = self.env["purchase.order.line"].create( |
||||
|
{ |
||||
|
"name": cpo_line.name, |
||||
|
"product_id": cpo_line.product_template_id.product_variant_id.id, |
||||
|
"product_qty": cpo_line.purchase_quantity, |
||||
|
"price_unit": cpo_line.product_price, |
||||
|
"product_uom": cpo_line.uom_po_id.id, |
||||
|
"order_id": purchase_order.id, |
||||
|
"date_planned": self.date_planned, |
||||
|
} |
||||
|
) |
||||
|
pol.compute_taxes_id() |
||||
|
|
||||
|
self.generated_purchase_order_ids += purchase_order |
||||
|
|
||||
|
action = { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"res_model": "purchase.order", |
||||
|
"res_id": purchase_order.id, |
||||
|
"view_type": "form", |
||||
|
"view_mode": "form,tree", |
||||
|
"target": "current", |
||||
|
} |
||||
|
return action |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("generated_purchase_order_ids") |
||||
|
def _compute_generated_po_count(self): |
||||
|
for cpo in self: |
||||
|
cpo.generated_po_count = len(cpo.generated_purchase_order_ids) |
||||
|
|
||||
|
@api.multi |
||||
|
def get_generated_po_action(self): |
||||
|
self.ensure_one() |
||||
|
action = { |
||||
|
"type": "ir.actions.act_window", |
||||
|
"res_model": "purchase.order", |
||||
|
"view_mode": "tree,form,kanban", |
||||
|
"target": "current", |
||||
|
"domain": [("id", "in", self.generated_purchase_order_ids.ids)], |
||||
|
} |
||||
|
return action |
@ -0,0 +1,181 @@ |
|||||
|
# Copyright 2020 Coop IT Easy SCRL fs |
||||
|
# Robin Keunen <robin@coopiteasy.be> |
||||
|
# Vincent Van Rossem <vincent@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
import logging |
||||
|
|
||||
|
from odoo import models, fields, api, _ |
||||
|
from odoo.exceptions import ValidationError |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class PurchaseOrderGeneratorLine(models.Model): |
||||
|
_description = "Purchase Order Generator Line" |
||||
|
_name = "purchase.order.generator.line" |
||||
|
|
||||
|
name = fields.Char(string="Product Name", compute="_compute_name") |
||||
|
cpo_id = fields.Many2one( |
||||
|
comodel_name="purchase.order.generator", |
||||
|
string="Purchase Order Generator", |
||||
|
) |
||||
|
product_template_id = fields.Many2one( |
||||
|
comodel_name="product.template", |
||||
|
string="Linked Product Template", |
||||
|
required=True, |
||||
|
help="Product", |
||||
|
) |
||||
|
purchase_quantity = fields.Float(string="Purchase Quantity", default=0.0) |
||||
|
category_id = fields.Many2one( |
||||
|
comodel_name="product.category", |
||||
|
string="Internal Category", |
||||
|
related="product_template_id.categ_id", |
||||
|
read_only=True, |
||||
|
) |
||||
|
uom_id = fields.Many2one( |
||||
|
comodel_name="uom.uom", |
||||
|
string="Unit of Measure", |
||||
|
read_only=True, |
||||
|
related="product_template_id.uom_id", |
||||
|
help="Default Unit of Measure used for all stock operation.", |
||||
|
) |
||||
|
qty_available = fields.Float( |
||||
|
string="Stock Quantity", |
||||
|
related="product_template_id.qty_available", |
||||
|
read_only=True, |
||||
|
help="Quantity currently in stock. Does not take " |
||||
|
"into account incoming orders.", |
||||
|
) |
||||
|
virtual_available = fields.Float( |
||||
|
string="Forecast Quantity", |
||||
|
related="product_template_id.virtual_available", |
||||
|
read_only=True, |
||||
|
help="Virtual quantity taking into account current stock, incoming " |
||||
|
"orders and outgoing sales.", |
||||
|
) |
||||
|
daily_sales = fields.Float( |
||||
|
string="Average Consumption", |
||||
|
related="product_template_id.daily_sales", |
||||
|
read_only=True, |
||||
|
) |
||||
|
stock_coverage = fields.Float( |
||||
|
string="Stock Coverage", |
||||
|
related="product_template_id.stock_coverage", |
||||
|
read_only=True, |
||||
|
) |
||||
|
uom_po_id = fields.Many2one( |
||||
|
comodel_name="uom.uom", |
||||
|
string="Purchase Unit of Measure", |
||||
|
read_only=True, |
||||
|
related="product_template_id.uom_po_id", |
||||
|
help="Default Unit of Measure used for all stock operation.", |
||||
|
) |
||||
|
supplierinfo_id = fields.Many2one( |
||||
|
comodel_name="product.supplierinfo", |
||||
|
string="Supplier information", |
||||
|
compute="_compute_supplierinfo", |
||||
|
store=True, |
||||
|
readonly=True, |
||||
|
) |
||||
|
minimum_purchase_qty = fields.Float( |
||||
|
string="Minimum Purchase Quantity", related="supplierinfo_id.min_qty" |
||||
|
) |
||||
|
product_price = fields.Float( |
||||
|
string="Product Price (w/o VAT)", |
||||
|
related="supplierinfo_id.price", |
||||
|
help="Supplier Product Price by buying unit. Price is without VAT", |
||||
|
) |
||||
|
virtual_coverage = fields.Float( |
||||
|
string="Expected Stock Coverage", |
||||
|
compute="_compute_coverage_and_subtotal", |
||||
|
help="Expected stock coverage (in days) based on current stocks and " |
||||
|
"average daily consumption", |
||||
|
) |
||||
|
subtotal = fields.Float( |
||||
|
string="Subtotal (w/o VAT)", compute="_compute_coverage_and_subtotal" |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("supplierinfo_id") |
||||
|
def _compute_name(self): |
||||
|
for cpol in self: |
||||
|
if cpol.supplierinfo_id and cpol.supplierinfo_id.product_code: |
||||
|
product_code = cpol.supplierinfo_id.product_code |
||||
|
product_name = cpol.product_template_id.name |
||||
|
cpol_name = "[%s] %s" % (product_code, product_name) |
||||
|
else: |
||||
|
cpol_name = cpol.product_template_id.name |
||||
|
cpol.name = cpol_name |
||||
|
|
||||
|
@api.multi |
||||
|
@api.onchange("product_template_id") |
||||
|
def _onchange_purchase_quantity(self): |
||||
|
for cpol in self: |
||||
|
cpol.purchase_quantity = cpol.minimum_purchase_qty |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("purchase_quantity") |
||||
|
def _compute_coverage_and_subtotal(self): |
||||
|
for cpol in self: |
||||
|
cpol.subtotal = cpol.product_price * cpol.purchase_quantity |
||||
|
avg = cpol.daily_sales |
||||
|
if avg > 0: |
||||
|
qty = (cpol.virtual_available / cpol.uom_id.factor) + ( |
||||
|
cpol.purchase_quantity / cpol.uom_po_id.factor |
||||
|
) |
||||
|
cpol.virtual_coverage = qty / avg |
||||
|
else: |
||||
|
# todo what would be a good default value? (not float(inf)) |
||||
|
cpol.virtual_coverage = 9999 |
||||
|
|
||||
|
return True |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("product_template_id") |
||||
|
def _compute_supplierinfo(self): |
||||
|
for cpol in self: |
||||
|
if not cpol.product_template_id: |
||||
|
continue |
||||
|
|
||||
|
si = self.env["product.supplierinfo"].search( |
||||
|
[ |
||||
|
("product_tmpl_id", "=", cpol.product_template_id.id), |
||||
|
("name", "=", cpol.cpo_id.supplier_id.id), |
||||
|
] |
||||
|
) |
||||
|
|
||||
|
if len(si) == 0: |
||||
|
raise ValidationError( |
||||
|
_("POG supplier does not sell product {name}").format( |
||||
|
name=cpol.product_template_id.name |
||||
|
) |
||||
|
) |
||||
|
elif len(si) > 1: |
||||
|
_logger.warning( |
||||
|
"product {name} has several supplier info set, chose last".format( |
||||
|
name=cpol.product_template_id.name |
||||
|
) |
||||
|
) |
||||
|
si = si.sorted(key=lambda r: r.create_date, reverse=True) |
||||
|
cpol.supplierinfo_id = si[0] |
||||
|
|
||||
|
@api.constrains("purchase_quantity") |
||||
|
def _check_minimum_purchase_quantity(self): |
||||
|
for cpol in self: |
||||
|
if cpol.purchase_quantity < 0: |
||||
|
raise ValidationError( |
||||
|
_( |
||||
|
"Purchase quantity for {product_name} " |
||||
|
"must be greater than 0" |
||||
|
).format(product_name=cpol.product_template_id.name) |
||||
|
) |
||||
|
elif 0 < cpol.purchase_quantity < cpol.minimum_purchase_qty: |
||||
|
raise ValidationError( |
||||
|
_( |
||||
|
"Purchase quantity for {product_name} " |
||||
|
"must be greater than {min_qty}" |
||||
|
).format( |
||||
|
product_name=cpol.product_template_id.name, |
||||
|
min_qty=cpol.minimum_purchase_qty, |
||||
|
) |
||||
|
) |
@ -0,0 +1,2 @@ |
|||||
|
* Robin Keunen <robin@coopiteasy.be> |
||||
|
* Vincent Van Rossem <vincent@coopiteasy.be> |
@ -0,0 +1 @@ |
|||||
|
Generate purchase order from a product selection. |
@ -0,0 +1,11 @@ |
|||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
||||
|
|
||||
|
access_purchase_order,purchase.order,model_purchase_order_generator,purchase.group_purchase_user,1,1,1,1 |
||||
|
access_purchase_order_manager,purchase.order,model_purchase_order_generator,purchase.group_purchase_manager,1,1,1,1 |
||||
|
access_purchase_order_stock_worker,purchase.order,model_purchase_order_generator,stock.group_stock_user,1,0,0,0 |
||||
|
access_purchase_order_invoicing_payments,purchase.order,model_purchase_order_generator,account.group_account_invoice,1,1,0,0 |
||||
|
|
||||
|
access_purchase_order_line,purchase.order.line user,model_purchase_order_generator_line,purchase.group_purchase_user,1,1,1,1 |
||||
|
access_purchase_order_line_manager,purchase.order.line manager,model_purchase_order_generator_line,purchase.group_purchase_manager,1,1,1,1 |
||||
|
access_purchase_order_line_stock_worker,purchase.order.line,model_purchase_order_generator_line,stock.group_stock_user,1,0,0,0 |
||||
|
access_purchase_order_line_invoicing_payments,purchase.order.line,model_purchase_order_generator_line,account.group_account_invoice,1,1,0,0 |
@ -0,0 +1,415 @@ |
|||||
|
<?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> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
|
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> |
||||
|
<title>Purchase Order Generator</title> |
||||
|
<style type="text/css"> |
||||
|
|
||||
|
/* |
||||
|
:Author: David Goodger (goodger@python.org) |
||||
|
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $ |
||||
|
:Copyright: This stylesheet has been placed in the public domain. |
||||
|
|
||||
|
Default cascading style sheet for the HTML output of Docutils. |
||||
|
|
||||
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to |
||||
|
customize this style sheet. |
||||
|
*/ |
||||
|
|
||||
|
/* used to remove borders from tables and images */ |
||||
|
.borderless, table.borderless td, table.borderless th { |
||||
|
border: 0 } |
||||
|
|
||||
|
table.borderless td, table.borderless th { |
||||
|
/* Override padding for "table.docutils td" with "! important". |
||||
|
The right padding separates the table cells. */ |
||||
|
padding: 0 0.5em 0 0 ! important } |
||||
|
|
||||
|
.first { |
||||
|
/* Override more specific margin styles with "! important". */ |
||||
|
margin-top: 0 ! important } |
||||
|
|
||||
|
.last, .with-subtitle { |
||||
|
margin-bottom: 0 ! important } |
||||
|
|
||||
|
.hidden { |
||||
|
display: none } |
||||
|
|
||||
|
.subscript { |
||||
|
vertical-align: sub; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
.superscript { |
||||
|
vertical-align: super; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
a.toc-backref { |
||||
|
text-decoration: none ; |
||||
|
color: black } |
||||
|
|
||||
|
blockquote.epigraph { |
||||
|
margin: 2em 5em ; } |
||||
|
|
||||
|
dl.docutils dd { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] { |
||||
|
overflow: hidden; |
||||
|
} |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms |
||||
|
dl.docutils dt { |
||||
|
font-weight: bold } |
||||
|
*/ |
||||
|
|
||||
|
div.abstract { |
||||
|
margin: 2em 5em } |
||||
|
|
||||
|
div.abstract p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
text-align: center } |
||||
|
|
||||
|
div.admonition, div.attention, div.caution, div.danger, div.error, |
||||
|
div.hint, div.important, div.note, div.tip, div.warning { |
||||
|
margin: 2em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.admonition p.admonition-title, div.hint p.admonition-title, |
||||
|
div.important p.admonition-title, div.note p.admonition-title, |
||||
|
div.tip p.admonition-title { |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
div.attention p.admonition-title, div.caution p.admonition-title, |
||||
|
div.danger p.admonition-title, div.error p.admonition-title, |
||||
|
div.warning p.admonition-title, .code .error { |
||||
|
color: red ; |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get reduced vertical space in |
||||
|
compound paragraphs. |
||||
|
div.compound .compound-first, div.compound .compound-middle { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
div.compound .compound-last, div.compound .compound-middle { |
||||
|
margin-top: 0.5em } |
||||
|
*/ |
||||
|
|
||||
|
div.dedication { |
||||
|
margin: 2em 5em ; |
||||
|
text-align: center ; |
||||
|
font-style: italic } |
||||
|
|
||||
|
div.dedication p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
font-style: normal } |
||||
|
|
||||
|
div.figure { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
div.footer, div.header { |
||||
|
clear: both; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
div.line-block { |
||||
|
display: block ; |
||||
|
margin-top: 1em ; |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
div.line-block div.line-block { |
||||
|
margin-top: 0 ; |
||||
|
margin-bottom: 0 ; |
||||
|
margin-left: 1.5em } |
||||
|
|
||||
|
div.sidebar { |
||||
|
margin: 0 0 0.5em 1em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em ; |
||||
|
background-color: #ffffee ; |
||||
|
width: 40% ; |
||||
|
float: right ; |
||||
|
clear: right } |
||||
|
|
||||
|
div.sidebar p.rubric { |
||||
|
font-family: sans-serif ; |
||||
|
font-size: medium } |
||||
|
|
||||
|
div.system-messages { |
||||
|
margin: 5em } |
||||
|
|
||||
|
div.system-messages h1 { |
||||
|
color: red } |
||||
|
|
||||
|
div.system-message { |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.system-message p.system-message-title { |
||||
|
color: red ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
div.topic { |
||||
|
margin: 2em } |
||||
|
|
||||
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, |
||||
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { |
||||
|
margin-top: 0.4em } |
||||
|
|
||||
|
h1.title { |
||||
|
text-align: center } |
||||
|
|
||||
|
h2.subtitle { |
||||
|
text-align: center } |
||||
|
|
||||
|
hr.docutils { |
||||
|
width: 75% } |
||||
|
|
||||
|
img.align-left, .figure.align-left, object.align-left, table.align-left { |
||||
|
clear: left ; |
||||
|
float: left ; |
||||
|
margin-right: 1em } |
||||
|
|
||||
|
img.align-right, .figure.align-right, object.align-right, table.align-right { |
||||
|
clear: right ; |
||||
|
float: right ; |
||||
|
margin-left: 1em } |
||||
|
|
||||
|
img.align-center, .figure.align-center, object.align-center { |
||||
|
display: block; |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
table.align-center { |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
.align-left { |
||||
|
text-align: left } |
||||
|
|
||||
|
.align-center { |
||||
|
clear: both ; |
||||
|
text-align: center } |
||||
|
|
||||
|
.align-right { |
||||
|
text-align: right } |
||||
|
|
||||
|
/* reset inner alignment in figures */ |
||||
|
div.align-right { |
||||
|
text-align: inherit } |
||||
|
|
||||
|
/* div.align-center * { */ |
||||
|
/* text-align: left } */ |
||||
|
|
||||
|
.align-top { |
||||
|
vertical-align: top } |
||||
|
|
||||
|
.align-middle { |
||||
|
vertical-align: middle } |
||||
|
|
||||
|
.align-bottom { |
||||
|
vertical-align: bottom } |
||||
|
|
||||
|
ol.simple, ul.simple { |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
ol.arabic { |
||||
|
list-style: decimal } |
||||
|
|
||||
|
ol.loweralpha { |
||||
|
list-style: lower-alpha } |
||||
|
|
||||
|
ol.upperalpha { |
||||
|
list-style: upper-alpha } |
||||
|
|
||||
|
ol.lowerroman { |
||||
|
list-style: lower-roman } |
||||
|
|
||||
|
ol.upperroman { |
||||
|
list-style: upper-roman } |
||||
|
|
||||
|
p.attribution { |
||||
|
text-align: right ; |
||||
|
margin-left: 50% } |
||||
|
|
||||
|
p.caption { |
||||
|
font-style: italic } |
||||
|
|
||||
|
p.credits { |
||||
|
font-style: italic ; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
p.label { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
p.rubric { |
||||
|
font-weight: bold ; |
||||
|
font-size: larger ; |
||||
|
color: maroon ; |
||||
|
text-align: center } |
||||
|
|
||||
|
p.sidebar-title { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold ; |
||||
|
font-size: larger } |
||||
|
|
||||
|
p.sidebar-subtitle { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
p.topic-title { |
||||
|
font-weight: bold } |
||||
|
|
||||
|
pre.address { |
||||
|
margin-bottom: 0 ; |
||||
|
margin-top: 0 ; |
||||
|
font: inherit } |
||||
|
|
||||
|
pre.literal-block, pre.doctest-block, pre.math, pre.code { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
pre.code .ln { color: grey; } /* line numbers */ |
||||
|
pre.code, code { background-color: #eeeeee } |
||||
|
pre.code .comment, code .comment { color: #5C6576 } |
||||
|
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } |
||||
|
pre.code .literal.string, code .literal.string { color: #0C5404 } |
||||
|
pre.code .name.builtin, code .name.builtin { color: #352B84 } |
||||
|
pre.code .deleted, code .deleted { background-color: #DEB0A1} |
||||
|
pre.code .inserted, code .inserted { background-color: #A3D289} |
||||
|
|
||||
|
span.classifier { |
||||
|
font-family: sans-serif ; |
||||
|
font-style: oblique } |
||||
|
|
||||
|
span.classifier-delimiter { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
span.interpreted { |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
span.option { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
span.pre { |
||||
|
white-space: pre } |
||||
|
|
||||
|
span.problematic { |
||||
|
color: red } |
||||
|
|
||||
|
span.section-subtitle { |
||||
|
/* font-size relative to parent (h1..h6 element) */ |
||||
|
font-size: 80% } |
||||
|
|
||||
|
table.citation { |
||||
|
border-left: solid 1px gray; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docinfo { |
||||
|
margin: 2em 4em } |
||||
|
|
||||
|
table.docutils { |
||||
|
margin-top: 0.5em ; |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
table.footnote { |
||||
|
border-left: solid 1px black; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docutils td, table.docutils th, |
||||
|
table.docinfo td, table.docinfo th { |
||||
|
padding-left: 0.5em ; |
||||
|
padding-right: 0.5em ; |
||||
|
vertical-align: top } |
||||
|
|
||||
|
table.docutils th.field-name, table.docinfo th.docinfo-name { |
||||
|
font-weight: bold ; |
||||
|
text-align: left ; |
||||
|
white-space: nowrap ; |
||||
|
padding-left: 0 } |
||||
|
|
||||
|
/* "booktabs" style (no vertical lines) */ |
||||
|
table.docutils.booktabs { |
||||
|
border: 0px; |
||||
|
border-top: 2px solid; |
||||
|
border-bottom: 2px solid; |
||||
|
border-collapse: collapse; |
||||
|
} |
||||
|
table.docutils.booktabs * { |
||||
|
border: 0px; |
||||
|
} |
||||
|
table.docutils.booktabs th { |
||||
|
border-bottom: thin solid; |
||||
|
text-align: left; |
||||
|
} |
||||
|
|
||||
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, |
||||
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { |
||||
|
font-size: 100% } |
||||
|
|
||||
|
ul.auto-toc { |
||||
|
list-style-type: none } |
||||
|
|
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="document" id="purchase-order-generator"> |
||||
|
<h1 class="title">Purchase Order Generator</h1> |
||||
|
|
||||
|
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> |
||||
|
<p><a class="reference external" 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" 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" href="https://github.com/beescoop/obeesdoo/tree/12.0/purchase_order_generator"><img alt="beescoop/obeesdoo" src="https://img.shields.io/badge/github-beescoop%2Fobeesdoo-lightgray.png?logo=github" /></a></p> |
||||
|
<p>Generate purchase order from a product selection.</p> |
||||
|
<p><strong>Table of contents</strong></p> |
||||
|
<div class="contents local topic" id="contents"> |
||||
|
<ul class="simple"> |
||||
|
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li> |
||||
|
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul> |
||||
|
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li> |
||||
|
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li> |
||||
|
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li> |
||||
|
</ul> |
||||
|
</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="bug-tracker"> |
||||
|
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1> |
||||
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/beescoop/obeesdoo/issues">GitHub Issues</a>. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
<a class="reference external" href="https://github.com/beescoop/obeesdoo/issues/new?body=module:%20purchase_order_generator%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> |
||||
|
<p>Do not contact contributors directly about support or help with technical issues.</p> |
||||
|
</div> |
||||
|
<div class="section" id="credits"> |
||||
|
<h1><a class="toc-backref" href="#id2">Credits</a></h1> |
||||
|
<div class="section" id="authors"> |
||||
|
<h2><a class="toc-backref" href="#id3">Authors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Coop IT Easy SCRLfs</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="contributors"> |
||||
|
<h2><a class="toc-backref" href="#id4">Contributors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Robin Keunen <<a class="reference external" href="mailto:robin@coopiteasy.be">robin@coopiteasy.be</a>></li> |
||||
|
<li>Vincent Van Rossem <<a class="reference external" href="mailto:vincent@coopiteasy.be">vincent@coopiteasy.be</a>></li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="maintainers"> |
||||
|
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2> |
||||
|
<p>This module is part of the <a class="reference external" href="https://github.com/beescoop/obeesdoo/tree/12.0/purchase_order_generator">beescoop/obeesdoo</a> project on GitHub.</p> |
||||
|
<p>You are welcome to contribute.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1 @@ |
|||||
|
from . import test_pog |
@ -0,0 +1,84 @@ |
|||||
|
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) |
||||
|
# @author: Robin Keunen <robin@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo.tests.common import TransactionCase, Form |
||||
|
|
||||
|
|
||||
|
class TestCPO(TransactionCase): |
||||
|
def setUp(self): |
||||
|
super().setUp() |
||||
|
|
||||
|
self.supplier = self.browse_ref("base.res_partner_1") |
||||
|
self.pproduct1 = self.browse_ref("product.product_product_25") |
||||
|
self.ptemplate1 = self.pproduct1.product_tmpl_id |
||||
|
self.pproduct2 = self.browse_ref("product.product_delivery_02") |
||||
|
self.ptemplate2 = self.pproduct2.product_tmpl_id |
||||
|
|
||||
|
def test_generate_cpo(self): |
||||
|
supplierinfo_obj = self.env["product.supplierinfo"] |
||||
|
supplierinfo = supplierinfo_obj.search( |
||||
|
[ |
||||
|
("name", "=", self.supplier.id), |
||||
|
("product_tmpl_id", "=", self.ptemplate1.id), |
||||
|
] |
||||
|
) |
||||
|
supplierinfo2 = supplierinfo_obj.search( |
||||
|
[ |
||||
|
("name", "=", self.supplier.id), |
||||
|
("product_tmpl_id", "=", self.ptemplate2.id), |
||||
|
] |
||||
|
) |
||||
|
|
||||
|
pog_obj = self.env["purchase.order.generator"] |
||||
|
pog_action = pog_obj.with_context( |
||||
|
active_ids=[self.ptemplate1.id] |
||||
|
).generate_cpo() |
||||
|
pog = pog_obj.browse(pog_action["res_id"]) |
||||
|
pogl = pog.pog_line_ids # expect one line |
||||
|
|
||||
|
self.assertEquals(pog.supplier_id, self.supplier) |
||||
|
self.assertEquals(pogl.product_template_id, self.ptemplate1) |
||||
|
self.assertEquals(pogl.product_price, supplierinfo.price) |
||||
|
self.assertEquals(pogl.purchase_quantity, supplierinfo.min_qty) |
||||
|
|
||||
|
# testing triggers |
||||
|
expected_subtotal = supplierinfo.price * supplierinfo.min_qty |
||||
|
self.assertEquals(pogl.subtotal, expected_subtotal) |
||||
|
|
||||
|
pogl.purchase_quantity = 4 |
||||
|
expected_subtotal = supplierinfo.price * 4 |
||||
|
self.assertEquals(pogl.subtotal, expected_subtotal) |
||||
|
|
||||
|
pog_form = Form(pog) |
||||
|
with pog_form.pog_line_ids.edit(index=0) as line_form: |
||||
|
line_form.product_template_id = self.ptemplate2 |
||||
|
self.assertEquals(line_form.product_template_id, self.ptemplate2) |
||||
|
pog = pog_form.save() |
||||
|
pogl = pog.pog_line_ids |
||||
|
|
||||
|
expected_subtotal = supplierinfo2.price * supplierinfo2.min_qty |
||||
|
self.assertEquals(pogl.product_price, supplierinfo2.price) |
||||
|
self.assertEquals(pogl.purchase_quantity, supplierinfo2.min_qty) |
||||
|
self.assertEquals(pogl.subtotal, expected_subtotal) |
||||
|
|
||||
|
def test_generate_po(self): |
||||
|
cpo_obj = self.env["purchase.order.generator"] |
||||
|
cpo_action = cpo_obj.with_context( |
||||
|
active_ids=[self.ptemplate1.id, self.ptemplate2.id] |
||||
|
).generate_cpo() |
||||
|
cpo = cpo_obj.browse(cpo_action["res_id"]) |
||||
|
po_action = cpo.create_purchase_order() |
||||
|
po = self.env["purchase.order"].browse(po_action["res_id"]) |
||||
|
|
||||
|
self.assertEquals(cpo.supplier_id, po.partner_id) |
||||
|
self.assertEquals(len(cpo.pog_line_ids), len(po.order_line)) |
||||
|
lines = zip( |
||||
|
cpo.pog_line_ids.sorted(lambda l: l.product_template_id), |
||||
|
po.order_line.sorted(lambda l: l.product_id.product_tmpl_id), |
||||
|
) |
||||
|
for cpol, pol in lines: |
||||
|
self.assertEquals( |
||||
|
cpol.product_template_id, pol.product_id.product_tmpl_id |
||||
|
) |
||||
|
self.assertEquals(cpol.purchase_quantity, pol.product_qty) |
@ -0,0 +1,23 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<odoo> |
||||
|
<record id="product_template_tree" model="ir.ui.view"> |
||||
|
<field name="name">product.template.tree</field> |
||||
|
<field name="model">product.template</field> |
||||
|
<field eval="6" name="priority"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
|
||||
|
<tree> |
||||
|
<field name="name"/> |
||||
|
<field name="ref interne"/> |
||||
|
<field name="supplier"/> |
||||
|
<field name="stock_coverage"/> |
||||
|
<field name="virtual_coverage"/> |
||||
|
<field name="categ_id"/> |
||||
|
<field name="qty_available"/> |
||||
|
<field name="expected quantity"/> |
||||
|
</tree> |
||||
|
|
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<record id="view_purchase_order_form_inherit" model="ir.ui.view"> |
||||
|
<field name="name">purchase.order.form.inherit</field> |
||||
|
<field name="model">purchase.order</field> |
||||
|
<field name="inherit_id" ref="purchase.purchase_order_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//field[@name='date_order']" position="after"> |
||||
|
<field name="original_cpo_id" attrs="{'invisible': [('original_cpo_id','=',False)]}"/> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,113 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!-- views--> |
||||
|
|
||||
|
<!--tree--> |
||||
|
<record id="purchase_order_generator_tree" model="ir.ui.view"> |
||||
|
<field name="name">purchase.order.generator.tree</field> |
||||
|
<field name="model">purchase.order.generator</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree> |
||||
|
<field name="name"/> |
||||
|
<field name="supplier_id"/> |
||||
|
<field name="order_date"/> |
||||
|
<field name="date_planned"/> |
||||
|
<field name="total_amount"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<!-- form --> |
||||
|
<record id="purchase_order_generator_form" model="ir.ui.view"> |
||||
|
<field name="name">purchase.order.generator.form</field> |
||||
|
<field name="model">purchase.order.generator</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form> |
||||
|
<header> |
||||
|
<button type="object" |
||||
|
name="create_purchase_order" |
||||
|
string="Create Purchase Order" |
||||
|
class="oe_highlight"/> |
||||
|
</header> |
||||
|
|
||||
|
<sheet> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="supplier_id"/> |
||||
|
<field name="order_date"/> |
||||
|
<field name="date_planned"/> |
||||
|
<field name="total_amount"/> |
||||
|
<field name="generated_purchase_order_ids" |
||||
|
invisible='1'/> |
||||
|
</group> |
||||
|
|
||||
|
<div name="buttons" class="oe_right oe_button_box"> |
||||
|
<button class="oe_inline oe_stat_button" |
||||
|
type="object" |
||||
|
icon="fa-shopping-cart" |
||||
|
name="get_generated_po_action" |
||||
|
help="Generated Purchase Orders"> |
||||
|
<field string="Purchase orders" |
||||
|
name="generated_po_count" |
||||
|
widget="statinfo"/> |
||||
|
</button> |
||||
|
</div> |
||||
|
|
||||
|
</group> |
||||
|
|
||||
|
<field name="pog_line_ids"> |
||||
|
<tree name="order_lines" string="Order Lines" |
||||
|
editable='bottom'> |
||||
|
<field name="product_template_id"/> |
||||
|
<field name="qty_available" readonly='1'/> |
||||
|
<field name="virtual_available" readonly='1'/> |
||||
|
<field name="uom_id" readonly='1'/> |
||||
|
<field name="daily_sales" readonly='1'/> |
||||
|
<field name="stock_coverage" readonly='1'/> |
||||
|
<field name="virtual_coverage" readonly='1'/> |
||||
|
<field name="product_price" readonly='1'/> |
||||
|
<field name="uom_po_id" readonly='1'/> |
||||
|
<field name="purchase_quantity"/> |
||||
|
<field name="subtotal" readonly='1'/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</sheet> |
||||
|
|
||||
|
|
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<!-- filters--> |
||||
|
<record id="purchase_order_generator_filter" model="ir.ui.view"> |
||||
|
<field name="model">purchase.order.generator</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search> |
||||
|
<field name="supplier_id"/> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<!-- Menu item --> |
||||
|
|
||||
|
<record id="action_purchase_order_generator" model="ir.actions.act_window"> |
||||
|
<field name="name">Purchase Order Generators</field> |
||||
|
<field name="res_model">purchase.order.generator</field> |
||||
|
</record> |
||||
|
|
||||
|
<menuitem id="purchase_order_generator" |
||||
|
parent="purchase.menu_procurement_management" |
||||
|
action="action_purchase_order_generator"/> |
||||
|
|
||||
|
<!-- Actions --> |
||||
|
|
||||
|
<record id="action_generate_cpo" model="ir.actions.server"> |
||||
|
<field name="name">Generate Purchase Order</field> |
||||
|
<field name="model_id" ref="model_purchase_order_generator"/> |
||||
|
<field name="binding_model_id" ref="product.model_product_template"/> |
||||
|
<field name="state">code</field> |
||||
|
<field name="code"> |
||||
|
action = model.generate_cpo() |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue