[14.0][MIG] contract_sale_generation

This commit is contained in:
Freni-OSI
2021-04-21 13:42:13 +05:30
committed by Denis Roussel
parent 85d1264ffd
commit 0fe90c96ad
5 changed files with 18 additions and 37 deletions

View File

@@ -10,7 +10,7 @@
"license": "AGPL-3", "license": "AGPL-3",
"author": "PESOL, " "Odoo Community Association (OCA)", "author": "PESOL, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract", "website": "https://github.com/OCA/contract",
"depends": ["contract", "sale"], "depends": ["contract_sale"],
"data": [ "data": [
"data/contract_cron.xml", "data/contract_cron.xml",
"views/contract.xml", "views/contract.xml",

View File

@@ -16,7 +16,6 @@ class ContractContract(models.Model):
sale_count = fields.Integer(compute="_compute_sale_count") sale_count = fields.Integer(compute="_compute_sale_count")
@api.multi
def _prepare_sale(self, date_ref): def _prepare_sale(self, date_ref):
self.ensure_one() self.ensure_one()
sale = self.env["sale.order"].new( sale = self.env["sale.order"].new(
@@ -36,7 +35,6 @@ class ContractContract(models.Model):
sale.onchange_partner_id() sale.onchange_partner_id()
return sale._convert_to_write(sale._cache) return sale._convert_to_write(sale._cache)
@api.multi
def _get_related_sales(self): def _get_related_sales(self):
self.ensure_one() self.ensure_one()
sales = ( sales = (
@@ -46,12 +44,10 @@ class ContractContract(models.Model):
) )
return sales return sales
@api.multi
def _compute_sale_count(self): def _compute_sale_count(self):
for rec in self: for rec in self:
rec.sale_count = len(rec._get_related_sales()) rec.sale_count = len(rec._get_related_sales())
@api.multi
def action_show_sales(self): def action_show_sales(self):
self.ensure_one() self.ensure_one()
tree_view = self.env.ref("sale.view_order_tree", raise_if_not_found=False) tree_view = self.env.ref("sale.view_order_tree", raise_if_not_found=False)
@@ -68,7 +64,6 @@ class ContractContract(models.Model):
action["views"] = [(tree_view.id, "tree"), (form_view.id, "form")] action["views"] = [(tree_view.id, "tree"), (form_view.id, "form")]
return action return action
@api.multi
def recurring_create_sale(self): def recurring_create_sale(self):
""" """
This method triggers the creation of the next sale order of the This method triggers the creation of the next sale order of the
@@ -87,7 +82,6 @@ class ContractContract(models.Model):
) )
return sales return sales
@api.multi
def _prepare_recurring_sales_values(self, date_ref=False): def _prepare_recurring_sales_values(self, date_ref=False):
""" """
This method builds the list of sales values to create, based on This method builds the list of sales values to create, based on
@@ -118,7 +112,6 @@ class ContractContract(models.Model):
contract_lines._update_recurring_next_date() contract_lines._update_recurring_next_date()
return sales_values return sales_values
@api.multi
def _recurring_create_sale(self, date_ref=False): def _recurring_create_sale(self, date_ref=False):
sales_values = self._prepare_recurring_sales_values(date_ref) sales_values = self._prepare_recurring_sales_values(date_ref)
so_rec = self.env["sale.order"].create(sales_values) so_rec = self.env["sale.order"].create(sales_values)
@@ -148,7 +141,7 @@ class ContractContract(models.Model):
date_ref = fields.Date.context_today(self) date_ref = fields.Date.context_today(self)
domain = self._get_contracts_to_invoice_domain(date_ref) domain = self._get_contracts_to_invoice_domain(date_ref)
domain.extend([("type", "=", "invoice")]) domain.extend([("type", "=", "invoice")])
invoices = self.env["account.invoice"] invoices = self.env["account.move"]
# Invoice by companies, so assignation emails get correct context # Invoice by companies, so assignation emails get correct context
companies_to_invoice = self.read_group(domain, ["company_id"], ["company_id"]) companies_to_invoice = self.read_group(domain, ["company_id"], ["company_id"])
for row in companies_to_invoice: for row in companies_to_invoice:

View File

@@ -1,13 +1,12 @@
# Copyright (C) 2020 Open Source Integrators # Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models from odoo import models
class ContractLine(models.Model): class ContractLine(models.Model):
_inherit = "contract.line" _inherit = "contract.line"
@api.multi
def _prepare_sale_line(self, order_id=False, sale_values=False): def _prepare_sale_line(self, order_id=False, sale_values=False):
self.ensure_one() self.ensure_one()
dates = self._get_period_to_invoice( dates = self._get_period_to_invoice(
@@ -16,7 +15,7 @@ class ContractLine(models.Model):
sale_line_vals = { sale_line_vals = {
"product_id": self.product_id.id, "product_id": self.product_id.id,
"product_uom_qty": self._get_quantity_to_invoice(*dates), "product_uom_qty": self._get_quantity_to_invoice(*dates),
"uom_id": self.uom_id.id, "product_uom": self.uom_id.id,
"discount": self.discount, "discount": self.discount,
"contract_line_id": self.id, "contract_line_id": self.id,
"display_type": self.display_type, "display_type": self.display_type,
@@ -25,17 +24,13 @@ class ContractLine(models.Model):
sale_line_vals["order_id"] = order_id.id sale_line_vals["order_id"] = order_id.id
order_line = ( order_line = (
self.env["sale.order.line"] self.env["sale.order.line"]
.with_context( .with_company(self.contract_id.company_id.id)
force_company=self.contract_id.company_id.id,
)
.new(sale_line_vals) .new(sale_line_vals)
) )
if sale_values and not order_id: if sale_values and not order_id:
sale = ( sale = (
self.env["sale.order"] self.env["sale.order"]
.with_context( .with_company(self.contract_id.company_id.id)
force_company=self.contract_id.company_id.id,
)
.new(sale_values) .new(sale_values)
) )
order_line.order_id = sale order_line.order_id = sale

View File

@@ -1,5 +1,4 @@
<odoo> <odoo>
<record id="contract_contract_form_view_recurring_sale_form" model="ir.ui.view"> <record id="contract_contract_form_view_recurring_sale_form" model="ir.ui.view">
<field name="name">contract.contract.form.recurring.sale.form</field> <field name="name">contract.contract.form.recurring.sale.form</field>
<field name="model">contract.contract</field> <field name="model">contract.contract</field>
@@ -7,14 +6,14 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[@name='recurring_invoices']" position="after"> <xpath expr="//group[@name='recurring_invoices']" position="after">
<group <group
col="4"
name="recurring_sale_or_invoicing" name="recurring_sale_or_invoicing"
string="Recurring Sales/Invoicing" string="Recurring Sales/Invoicing"
col="4"
> >
<field name="type" /> <field name="type" />
<field <field
name="sale_autoconfirm"
attrs="{'invisible':[('type','!=', 'sale')]}" attrs="{'invisible':[('type','!=', 'sale')]}"
name="sale_autoconfirm"
/> />
</group> </group>
</xpath> </xpath>
@@ -28,34 +27,30 @@
</xpath> </xpath>
<xpath expr="//button[@name='recurring_create_invoice']" position="before"> <xpath expr="//button[@name='recurring_create_invoice']" position="before">
<button <button
name="recurring_create_sale"
type="object"
attrs="{'invisible': [('type','!=','sale')]}" attrs="{'invisible': [('type','!=','sale')]}"
string="CREATE SALES"
class="oe_link" class="oe_link"
groups="base.group_no_one" groups="base.group_no_one"
name="recurring_create_sale"
string="CREATE SALES"
type="object"
/> />
</xpath> </xpath>
<xpath <xpath expr="//button[@name='action_show_invoices']" position="attributes">
expr="//button[@name='action_show_invoices']"
position="attributes"
>
<attribute <attribute
name="attrs" name="attrs"
>{'invisible': [('type','!=','invoice')]}</attribute> >{'invisible': [('type','!=','invoice')]}</attribute>
</xpath> </xpath>
<xpath expr="//button[@name='action_show_invoices']" position="after"> <xpath expr="//button[@name='action_show_invoices']" position="after">
<button <button
attrs="{'invisible': [('type','!=','sale')]}"
class="oe_stat_button"
icon="fa-list"
name="action_show_sales" name="action_show_sales"
type="object" type="object"
icon="fa-list"
class="oe_stat_button"
attrs="{'invisible': [('type','!=','sale')]}"
> >
<field string="Sales Order" name="sale_count" widget="statinfo" /> <field name="sale_count" string="Sales Order" widget="statinfo" />
</button> </button>
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -1,5 +1,4 @@
<odoo> <odoo>
<record id="contract_template_form_view_inherit_sale" model="ir.ui.view"> <record id="contract_template_form_view_inherit_sale" model="ir.ui.view">
<field name="name">contract.template form view (in contract)</field> <field name="name">contract.template form view (in contract)</field>
<field name="model">contract.template</field> <field name="model">contract.template</field>
@@ -10,5 +9,4 @@
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>