Browse Source

[FIX] - Remove recurring_next_date from sale order line

recurring_next_date should be computed by contract line to get default value
pull/208/head
sbejaoui 6 years ago
committed by Thomas Binsfeld
parent
commit
3c882b6764
  1. 2
      product_contract/models/contract_line.py
  2. 14
      product_contract/models/sale_order.py
  3. 13
      product_contract/models/sale_order_line.py
  4. 3
      product_contract/views/sale_order.xml

2
product_contract/models/contract_line.py

@ -2,7 +2,7 @@
# 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, fields, models, _
from odoo import fields, models
class AccountAnalyticInvoiceLine(models.Model): class AccountAnalyticInvoiceLine(models.Model):

14
product_contract/models/sale_order.py

@ -26,6 +26,7 @@ class SaleOrder(models.Model):
line_to_create_contract = rec.order_line.filtered( line_to_create_contract = rec.order_line.filtered(
lambda r: not r.contract_id lambda r: not r.contract_id
) )
line_to_update_contract = rec.order_line.filtered('contract_id')
for contract_template in line_to_create_contract.mapped( for contract_template in line_to_create_contract.mapped(
'product_id.contract_template_id' 'product_id.contract_template_id'
): ):
@ -47,7 +48,6 @@ class SaleOrder(models.Model):
contract._onchange_contract_template_id() contract._onchange_contract_template_id()
order_lines.create_contract_line(contract) order_lines.create_contract_line(contract)
order_lines.write({'contract_id': contract.id}) order_lines.write({'contract_id': contract.id})
line_to_update_contract = rec.order_line.filtered('contract_id')
for line in line_to_update_contract: for line in line_to_update_contract:
line.create_contract_line(line.contract_id) line.create_contract_line(line.contract_id)
return super(SaleOrder, self).action_confirm() return super(SaleOrder, self).action_confirm()
@ -64,10 +64,10 @@ class SaleOrder(models.Model):
action = self.env.ref( action = self.env.ref(
"contract.action_account_analytic_sale_overdue_all" "contract.action_account_analytic_sale_overdue_all"
).read()[0] ).read()[0]
contracts = self.env['account.analytic.invoice.line'].search([
('sale_order_line', 'in', self.order_line.ids)
]).mapped('contract_id')
action["domain"] = [
("id", "in", contracts.ids)
]
contracts = (
self.env['account.analytic.invoice.line']
.search([('sale_order_line_id', 'in', self.order_line.ids)])
.mapped('contract_id')
)
action["domain"] = [("id", "in", contracts.ids)]
return action return action

13
product_contract/models/sale_order_line.py

@ -20,7 +20,7 @@ class SaleOrderLine(models.Model):
comodel_name='account.analytic.contract', comodel_name='account.analytic.contract',
string='Contract Template', string='Contract Template',
related='product_id.product_tmpl_id.contract_template_id', related='product_id.product_tmpl_id.contract_template_id',
readonly=True
readonly=True,
) )
recurring_rule_type = fields.Selection( recurring_rule_type = fields.Selection(
[ [
@ -50,9 +50,6 @@ class SaleOrderLine(models.Model):
) )
date_start = fields.Date(string='Date Start', default=fields.Date.today()) date_start = fields.Date(string='Date Start', default=fields.Date.today())
date_end = fields.Date(string='Date End', index=True) date_end = fields.Date(string='Date End', index=True)
recurring_next_date = fields.Date(
default=fields.Date.today(), copy=False, string='Date of Next Invoice'
)
@api.onchange('product_id') @api.onchange('product_id')
def onchange_product(self): def onchange_product(self):
@ -74,8 +71,6 @@ class SaleOrderLine(models.Model):
'uom_id': self.product_uom.id, 'uom_id': self.product_uom.id,
'price_unit': self.price_unit, 'price_unit': self.price_unit,
'discount': self.discount, 'discount': self.discount,
'recurring_next_date': self.recurring_next_date
or fields.Date.today(),
'date_end': self.date_end, 'date_end': self.date_end,
'date_start': self.date_start or fields.Date.today(), 'date_start': self.date_start or fields.Date.today(),
'recurring_interval': self.recurring_interval, 'recurring_interval': self.recurring_interval,
@ -87,9 +82,13 @@ class SaleOrderLine(models.Model):
@api.multi @api.multi
def create_contract_line(self, contract): def create_contract_line(self, contract):
contract_line_env = self.env['account.analytic.invoice.line']
contract_line = self.env['account.analytic.invoice.line'] contract_line = self.env['account.analytic.invoice.line']
for rec in self: for rec in self:
contract_line.create(rec._prepare_contract_line_values(contract))
contract_line |= contract_line_env.create(
rec._prepare_contract_line_values(contract)
)
contract_line._onchange_date_start()
@api.constrains('contract_id') @api.constrains('contract_id')
def _check_contract_sale_partner(self): def _check_contract_sale_partner(self):

3
product_contract/views/sale_order.xml

@ -56,7 +56,6 @@
</group> </group>
<group attrs="{'invisible': [('is_contract', '=', False)]}"> <group attrs="{'invisible': [('is_contract', '=', False)]}">
<field name="date_start"/> <field name="date_start"/>
<field name="recurring_next_date"/>
</group> </group>
<group attrs="{'invisible': [('is_contract', '=', False)]}"> <group attrs="{'invisible': [('is_contract', '=', False)]}">
<field name="date_end"/> <field name="date_end"/>
@ -68,8 +67,6 @@
attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/> attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/>
<field name="date_end" <field name="date_end"
attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/> attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/>
<field name="recurring_next_date"
attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/>
</xpath> </xpath>
<xpath expr="//field[@name='order_line']/tree" <xpath expr="//field[@name='order_line']/tree"
position="attributes"> position="attributes">

Loading…
Cancel
Save