Skip to content
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
104 changes: 104 additions & 0 deletions l10n_br_purchase_blanket_order/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
=============================================
Brazilian Localization Purchase Blanket Order
=============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5321fd857e1404d9b0d7a742156343473434e778d772df579379da429e3ec2d5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-OCA%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-brazil/tree/16.0/l10n_br_purchase_blanket_order
:alt: OCA/l10n-brazil
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-brazil-16-0/l10n-brazil-16-0-l10n_br_purchase_blanket_order
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the Odoo Purchase Blanket Order module to adapt it
to the Brazilian needs, with this module you have tax data for
collection and generation of fiscal documents (NF-e, NFS-e, CF-e, NFC-e
and others), calculation Brazilian taxes and contributions (municipal,
state and federal).

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Go to Purchase
2. Create or select a Purchase Blanket Order
3. Confirm the Purchase Blanket Order
4. Create Purchase Order

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-brazil/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-brazil/issues/new?body=module:%20l10n_br_purchase_blanket_order%0Aversion:%2016.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
-------

* Escodoo

Contributors
------------

- `Escodoo <https://www.escodoo.com.br>`__:

- Marcel Savegnago <[email protected]>
- Wesley Oliveira <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-WesleyOlivera98| image:: https://github.com/WesleyOlivera98.png?size=40px
:target: https://github.com/WesleyOlivera98
:alt: WesleyOlivera98
.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px
:target: https://github.com/marcelsavegnago
:alt: marcelsavegnago

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-WesleyOlivera98| |maintainer-marcelsavegnago|

This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/16.0/l10n_br_purchase_blanket_order>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions l10n_br_purchase_blanket_order/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
20 changes: 20 additions & 0 deletions l10n_br_purchase_blanket_order/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2026 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Brazilian Localization Purchase Blanket Order",
"summary": """
Brazilian Localization Purchase Blanket Order""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo, Odoo Community Association (OCA)",
"maintainers": ["WesleyOlivera98", "marcelsavegnago"],
"website": "https://github.com/OCA/l10n-brazil",
"depends": ["purchase_blanket_order", "l10n_br_purchase"],
"data": [
"views/purchase_blanket_order.xml",
"views/purchase_blanket_order_line.xml",
],
"installable": True,
"auto_install": False,
}
2 changes: 2 additions & 0 deletions l10n_br_purchase_blanket_order/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase_blanket_order
from . import purchase_blanket_order_line
91 changes: 91 additions & 0 deletions l10n_br_purchase_blanket_order/models/purchase_blanket_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2026 - TODAY, Wesley Oliveira <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseBlanketOrder(models.Model):
_name = "purchase.blanket.order"
_inherit = [_name, "l10n_br_fiscal.document.mixin"]

@api.model
def _default_fiscal_operation(self):
return self.env.company.purchase_fiscal_operation_id

@api.model
def _fiscal_operation_domain(self):
return [("state", "=", "approved")]

fiscal_operation_id = fields.Many2one(
comodel_name="l10n_br_fiscal.operation",
readonly=True,
states={"draft": [("readonly", False)]},
default=_default_fiscal_operation,
domain=lambda self: self._fiscal_operation_domain(),
)
ind_pres = fields.Selection(
readonly=True,
states={"draft": [("readonly", False)]},
)
cnpj_cpf = fields.Char(
string="CNPJ/CPF",
related="partner_id.vat",
)
legal_name = fields.Char(
string="Legal Name",
related="partner_id.legal_name",
)
l10n_br_ie_code = fields.Char(
string="State Tax Number/RG",
related="partner_id.l10n_br_ie_code",
)
comment_ids = fields.Many2many(
comodel_name="l10n_br_fiscal.comment",
relation="purchase_blanket_order_comment_rel",
column1="purchase_blanket_order_id",
column2="comment_id",
string="Comments",
)
operation_name = fields.Char(copy=False)

@api.model
def _get_fiscal_lines_field_name(self):
return "line_ids"

def _get_amount_lines(self):
return self.mapped("line_ids")

@api.depends("line_ids")
def _compute_amount(self):
return super()._compute_amount_all()

@api.depends("line_ids.price_total")
def _amount_all(self):
for order in self:
order._compute_amount()

@api.model
def fields_view_get(
self, view_id=None, view_type="form", toolbar=False, submenu=False
):
order_view = super().fields_view_get(view_id, view_type, toolbar, submenu)

if view_type == "form":
view = self.env["ir.ui.view"]
sub_form_view = order_view["fields"]["line_ids"]["views"]["form"]["arch"]
sub_form_node = self.env[
"purchase.blanket.order.line"
].inject_fiscal_fields(sub_form_view)
sub_arch, sub_fields = view.postprocess_and_fields(
sub_form_node, "purchase.blanket.order.line", False
)
order_view["fields"]["line_ids"]["views"]["form"] = {
"fields": sub_fields,
"arch": sub_arch,
}

return order_view

@api.onchange("fiscal_operation_id")
def _onchange_fiscal_operation_id(self):
self.fiscal_position_id = self.fiscal_operation_id.fiscal_position_id
175 changes: 175 additions & 0 deletions l10n_br_purchase_blanket_order/models/purchase_blanket_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Copyright 2026 - TODAY, Wesley Oliveira <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseBlanketOrderLine(models.Model):
_name = "purchase.blanket.order.line"
_inherit = [_name, "l10n_br_fiscal.document.line.mixin"]

country_id = fields.Many2one(related="company_id.country_id", store=True)

@api.model
def _fiscal_operation_domain(self):
return [("state", "=", "approved")]

fiscal_operation_id = fields.Many2one(
comodel_name="l10n_br_fiscal.operation",
domain=lambda self: self._fiscal_operation_domain(),
)
fiscal_operation_line_id = fields.Many2one(
comodel_name="l10n_br_fiscal.operation.line",
string="Operation Line",
domain="[('fiscal_operation_id', '=', fiscal_operation_id), "
"('state', '=', 'approved')]",
)
fiscal_tax_ids = fields.Many2many(
comodel_name="l10n_br_fiscal.tax",
relation="fiscal_purchase_blanket_order_line_tax_rel",
column1="document_id",
column2="fiscal_tax_id",
string="Fiscal Taxes",
)
quantity = fields.Float(
string="Product Uom Quantity",
related="original_uom_qty",
)
uom_id = fields.Many2one(
related="product_uom",
)
tax_framework = fields.Selection(
related="order_id.company_id.tax_framework",
string="Tax Framework",
)
partner_id = fields.Many2one(
comodel_name="res.partner",
related="order_id.partner_id",
string="Partner",
)
price_gross = fields.Monetary(
compute="_compute_amount", string="Gross Amount", compute_sudo=True
)
comment_ids = fields.Many2many(
comodel_name="l10n_br_fiscal.comment",
relation="purchase_blanket_order_line_comment_rel",
column1="purchase_blanket_order_line_id",
column2="comment_id",
string="Comments",
)
ind_final = fields.Selection(related="order_id.ind_final")
price_subtotal = fields.Monetary(compute_sudo=True)
price_tax = fields.Monetary(compute_sudo=True)
price_total = fields.Monetary(compute_sudo=True)

@api.model
def _cnae_domain(self):
company = self.env.company
domain = []
if company.cnae_main_id and company.cnae_secondary_ids:
cnae_main_id = company.cnae_main_id.id
cnae_secondary_ids = company.cnae_secondary_ids.ids
domain = [
"|",
("id", "in", cnae_secondary_ids),
("id", "=", cnae_main_id),
]
return domain

cnae_id = fields.Many2one(
comodel_name="l10n_br_fiscal.cnae",
string="CNAE Code",
domain=lambda self: self._cnae_domain(),
)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
product_id = vals.get("product_id")
if product_id:
product = self.env["product.product"].browse(product_id)
vals["product_uom"] = product.uom_po_id.id or product.uom_id.id
vals["uom_id"] = vals["product_uom"]
vals["uot_id"] = vals["product_uom"]
return super().create(vals_list)

def _get_protected_fields(self):
protected_fields = super()._get_protected_fields()
return protected_fields + [
"fiscal_tax_ids",
"fiscal_operation_id",
"fiscal_operation_line_id",
]

@api.depends(
"partner_id",
"fiscal_tax_ids",
"product_id",
"price_unit",
"quantity",
"uom_id",
"fiscal_price",
"fiscal_quantity",
"uot_id",
"discount_value",
"insurance_value",
"ii_customhouse_charges",
"ii_iof_value",
"other_value",
"freight_value",
"ncm_id",
"nbs_id",
"nbm_id",
"cest_id",
"fiscal_operation_line_id",
"cfop_id",
"icmssn_range_id",
"icms_origin",
"icms_cst_id",
"ind_final",
"icms_relief_id",
"order_id.company_id",
"order_id.currency_id",
)
def _compute_tax_fields(self):
for line in self:
line.company_id = line.order_id.company_id
line.currency_id = line.order_id.currency_id
return super()._compute_tax_fields()

@api.depends(
"quantity",
"price_unit",
"fiscal_price",
"fiscal_quantity",
"fiscal_tax_ids",
)
def _compute_amount(self):
result = super()._compute_amount()
for line in self:
line.update(
{
"price_subtotal": line.fiscal_amount_untaxed,
"price_tax": line.fiscal_amount_tax,
"price_gross": line.fiscal_amount_untaxed,
"price_total": line.fiscal_amount_total,
}
)
return result

def _compute_price_unit_fiscal(self):
for line in self:
if line.fiscal_operation_id.default_price_unit == "cost_price":
line.price_unit = line.product_id._get_tax_included_unit_price(
line.company_id,
line.order_id.currency_id,
line.order_id.date_start,
"purchase",
fiscal_position=line.order_id.fiscal_position_id,
product_price_unit=line.price_unit,
product_currency=line.order_id.currency_id,
)
elif line.fiscal_operation_id.default_price_unit == "sale_price":
line.price_unit = line.product_id.lst_price
else:
line.price_unit = 0.00
Loading
Loading