@ -7,12 +7,12 @@ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class Computed PurchaseOrder( models . Model ) :
_description = " Computed Purchase Order"
_name = " computed. purchase.order"
class PurchaseOrderGenerato r ( models . Model ) :
_description = " Purchase Order Generato r "
_name = " purchase.order.generato r "
_order = " id desc "
name = fields . Char ( string = " C PO Reference" , default = _ ( " New " ) )
name = fields . Char ( string = " POG Reference " , default = _ ( " New " ) )
order_date = fields . Datetime (
string = " Purchase Order Date " ,
default = fields . Datetime . now ,
@ -21,7 +21,7 @@ class ComputedPurchaseOrder(models.Model):
)
date_planned = fields . Datetime (
string = " Date Planned " ,
default = fields . Datetime . now , # default=lambda _: fields.Datetime.now()
default = fields . Datetime . now ,
)
supplier_id = fields . Many2one (
comodel_name = " res.partner " ,
@ -29,13 +29,13 @@ class ComputedPurchaseOrder(models.Model):
readonly = True ,
help = " Supplier of the purchase order. " ,
)
c po_line_ids = fields . One2many (
comodel_name = " computed. purchase.order.line" ,
pog _line_ids = fields . One2many (
comodel_name = " purchase.order.generato r.line " ,
inverse_name = " cpo_id " ,
string = " Order Lines " ,
)
total_amount = fields . Float (
string = " Total Amount (w/o VAT) " , compute = " _ compute_c po_total"
string = " Total Amount (w/o VAT) " , compute = " compute_pog _total "
)
generated_purchase_order_ids = fields . One2many (
comodel_name = " purchase.order " ,
@ -48,10 +48,10 @@ class ComputedPurchaseOrder(models.Model):
)
@api.multi
@api.depends ( " c po_line_ids" , " c po_line_ids.purchase_quantity" )
def _ compute_c po_total( self ) :
@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 . c po_line_ids)
total_amount = sum ( cpol . subtotal for cpol in cpo . pog _line_ids )
cpo . total_amount = total_amount
@api.model
@ -71,11 +71,11 @@ class ComputedPurchaseOrder(models.Model):
@api.model
def generate_cpo ( self ) :
order_line_obj = self . env [ " computed. purchase.order.line" ]
order_line_obj = self . env [ " purchase.order.generato r.line " ]
product_ids = self . env . context . get ( " active_ids " , [ ] )
supplier = self . _get_selected_supplier ( )
name = " C PO {} {}" . format ( supplier . name , fields . Date . today ( ) )
name = " POG {} {} " . format ( supplier . name , fields . Date . today ( ) )
cpo = self . create ( { " name " : name , " supplier_id " : supplier . id } )
for product_id in product_ids :
@ -95,7 +95,7 @@ class ComputedPurchaseOrder(models.Model):
)
action = {
" type " : " ir.actions.act_window " ,
" res_model " : " computed. purchase.order" ,
" res_model " : " purchase.order.generato r " ,
" res_id " : cpo . id ,
" view_type " : " form " ,
" view_mode " : " form,tree " ,
@ -107,7 +107,7 @@ class ComputedPurchaseOrder(models.Model):
def create_purchase_order ( self ) :
self . ensure_one ( )
if sum ( self . c po_line_ids. mapped ( " purchase_quantity " ) ) == 0 :
if sum ( self . pog _line_ids . mapped ( " purchase_quantity " ) ) == 0 :
raise ValidationError (
" You need at least a product to generate " " a Purchase Order "
)
@ -120,7 +120,7 @@ class ComputedPurchaseOrder(models.Model):
}
)
for cpo_line in self . c po_line_ids:
for cpo_line in self . pog _line_ids :
if cpo_line . purchase_quantity > 0 :
pol = self . env [ " purchase.order.line " ] . create (
{