You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
73 lines
2.2 KiB
# Copyright 2016 Akretion Mourad EL HADJ MIMOUNE
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class PurchaseTest(models.Model):
|
|
_inherit = 'base.exception'
|
|
_name = "base.exception.test.purchase"
|
|
_description = "Base Ecxeption Test Model"
|
|
|
|
rule_group = fields.Selection(
|
|
selection_add=[('test_base', 'test')],
|
|
default='test_base',
|
|
)
|
|
name = fields.Char(required=True)
|
|
user_id = fields.Many2one('res.users', string='Responsible')
|
|
state = fields.Selection(
|
|
[('draft', 'New'), ('cancel', 'Cancelled'),
|
|
('purchase', 'Purchase'),
|
|
('to approve', 'To approve'), ('done', 'Done')],
|
|
string="Status", readonly=True, default='draft')
|
|
active = fields.Boolean(default=True)
|
|
partner_id = fields.Many2one('res.partner', string='Partner')
|
|
line_ids = fields.One2many(
|
|
'base.exception.test.purchase.line', 'lead_id')
|
|
amount_total = fields.Float(
|
|
compute='_compute_amount_total', store=True)
|
|
|
|
@api.depends('line_ids')
|
|
def _compute_amount_total(cls):
|
|
for record in cls:
|
|
for line in record.line_ids:
|
|
record.amount_total += line.amount * line.qty
|
|
|
|
@api.constrains('ignore_exception', 'line_ids', 'state')
|
|
def test_purchase_check_exception(cls):
|
|
orders = cls.filtered(lambda s: s.state == 'purchase')
|
|
if orders:
|
|
orders._check_exception()
|
|
|
|
@api.multi
|
|
def button_approve(cls, force=False):
|
|
cls.write({'state': 'to approve'})
|
|
return {}
|
|
|
|
@api.multi
|
|
def button_draft(cls):
|
|
cls.write({'state': 'draft'})
|
|
return {}
|
|
|
|
@api.multi
|
|
def button_confirm(cls):
|
|
cls.write({'state': 'purchase'})
|
|
return True
|
|
|
|
@api.multi
|
|
def button_cancel(cls):
|
|
cls.write({'state': 'cancel'})
|
|
|
|
def test_base_get_lines(cls):
|
|
cls.ensure_one()
|
|
return cls.line_ids
|
|
|
|
|
|
class LineTest(models.Model):
|
|
_name = "base.exception.test.purchase.line"
|
|
_description = "Base Exception Test Model Line"
|
|
|
|
name = fields.Char()
|
|
lead_id = fields.Many2one('base.exception.test.purchase',
|
|
ondelete='cascade')
|
|
qty = fields.Float()
|
|
amount = fields.Float()
|