Odoo 9.0C: How can i access the value of a many2one field (that has been created in sale.order.line module on the invoice qweb report? - odoo-9

I have installed module Sale Sourced by Line
by Camptocamp, Eficent, SerpentCS, Odoo Community Association (OCA) for Odoo 9.0.
The module creates a new many2one field as the code bellow:
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
warehouse_id = fields.Many2one(
'stock.warehouse',
'Source Warehouse',
readonly=True,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
help="If a source warehouse is selected, "
"it will be used to define the route. "
"Otherwise, it will get the warehouse of "
"the sale order")
Now i would like to access the value warehouse_id on account_invoice_report qweb. Please tell me what are posible solutions for my purpose? Thank for your time,

In account.invoice.line one field available sale_line_ids, based on that you can search warehouse_id from sale.order.line.
invoice.invoice_line_ids.mapped('sale_line_ids').mapped('warehouse_id')
This may help you.

Related

sql_cosntraints on exitsing field from original module

In product.template there is field default_code. Is it' possible to add sql_constraints that default code should be unique. Because this code doesn't work. Or do i need override default_code field in my costume module?
class ProductProduct(models.Model):
_inherit = 'product.template'
_sql_constraints = [
('code_uniq', 'unique (default_code)', "Default code already exists!"),
]
Please try with Python constrain may its useful for you :
import this lines in python file :
from openerp.exceptions import ValidationError
Any write this method in your class :
#api.constrains('default_code')
def _check_default_code(self):
code = self.search([('default_code','=',self.default_code)])
if len(code) > 1:
raise ValidationError(_("Duplicate Record"))
I would add the constraint on model product.product because that's where this information (product reference) really is used. But default_code on product.template will only work since Odoo V10. In Odoo V8 and V9 it was a unstored related field, so not in DB. So you have to add the constraint on model product.product.
class ProductProduct(models.Model):
_inherit = 'product.product'
_sql_constraints = [
('code_uniq', 'unique(default_code)', "Default code already exists!"),
]
Important to know: If the module, which sets up the constraint, is updated while the constraint will fail (e. g. the default_code actually twice in db), it won't create a sql constraint in db. So you have to clean up the data and update the module again or create the constraint in the db by yourself.

Odoo how domain attribute works?

I have a One2many relation in my odoo ' student .student' model that's it
result_ids = fields.One2many("schoolresults.detail", "student_id", "SchoolResults")
"schoolresults.detail" model has the following Many2One relational fields
student_id = fields.Many2one("student.student", "Student", ondelete="cascade")
subject_id = fields.Many2one("schoolresults.subject", "Subject")
The problem is when adding the result ids field its possible to add some subject twice to the same student and with a different scores .
I tried to make sql_constrait 'UNIQUE (student_id, subject_id)' on schoolresults.detail
Model but it raises an error .
I don’t want the subject to appear on the selction field if it is already selected.
I think the answer is arround domain attribute,
this image may cover my language faults.
enter image description here
you should return a domain on onchange of your one2many field result_ids.
eg:
ids_list = []
#api.onchnage('result_ids')
def onchange_result_ids(self):
for record in self.result_ids:
if record.subject_id:
ids_list.append(record.subject_id.id)
return {'domain': {'subject_id': [('id', 'not in', ids_list)]}}

Odoo 8/9/10 API, how to create an invoice from a sale order via XMLRPC

I'm developing a ruby application which sends some commands to Odoo via XMLRCP API.
I've been able to create a sale order in this whay
def execute_odoo_command(odoo_model, odoo_command, values)
#models.execute_kw(ODOO_DB, #uid, ODOO_PASSWORD, odoo_model, odoo_command, values)
end
def create_order_sale
order_reference = "SO #{#reference_code}_#{#customer_odoo_id}"
values = {
currency_id: 1,
date_order: Date.today.to_s,
name: order_reference,
payment_term: 1,
partner_id: #customer_odoo_id
}
order_id = execute_odoo_command('sale.order', 'create', [values])
create_sale_order_lines(order_id)
execute_odoo_command('sale.order', 'action_confirm', [order_id])
end
Now, I would launch the invoice creation. I have found a way to do it like this
execute_odoo_command('account.invoice', 'create', [invoice_values(order_reference)])
But, even if the invoice is created, the sale order is stil "open" and I can create another invoice from the Odoo interface clicking on "Create Invoice" button (which is obviously wrong). Is there any way to simulate that action via API?
The debug mode does not show any method in the tooltip.
Any suggestion is appreciated, thank you!
For future googlers. The solution is that I'm using an old API version. the right command call is this one
def create_invoice_from_sale_order(sale_order_id)
sale_order_to_invoice_data = [sale_order_id, {context: {active_ids: sale_order_id}}]
#odoo_rpc_client.execute_odoo_command('sale.order', 'action_invoice_create', sale_order_to_invoice_data)
end

How to make the form view opened from another form view read only in odoo

In my module i have two models, book and room. In room i will keep room details. In book i will keep the booking details of room. I have a many2one field in book model relating to room model. When i save the record of book, near to the many2one field a redirecting button will come. On clicking that, it will open the form view of room model. I want to make the second form view to be read only. How can i do that?. I tried to keep only read access for room model, then i can't able to save book model record. So how can i complete
class room(models.Model):
_name = 'room'
name = fields.Char('room name')
class book(models.Model):
_name = 'book'
name = fields.Char('booking person')
time = fields.Datetime('time')
room_name = fields.Many2one('room','room name')
Hello First take one boolean(like temp_bool) in room object,
now in book object, when you select room then write temp_bool field as True in selected room,
now based on this boolean you can give attrs in room object like attrs="{'readonly': [('temp_bool','=','True')]}"

Mezzanine Forms Dropdown

I'm trying out Django/Mezzanine and if I have a custom user profile as such:
class UserProfile(models.Model):
user = models.OneToOneField("auth.User")
street_address1 = models.CharField(max_length=100)
street_address2 = models.CharField(max_length=100)
postalcode = models.CharField(max_length=10)
city = models.CharField(max_length=32)
country = models.CharField(max_length=2)
phone = models.CharField(max_length=15)
Mezzanine creates a sign up form at account/signup/ and I would like to modify the Country field to have a drop down list of countries from a table or xml file. The foreign key is a two character field.
How should go about doing this? Do I create a model form or try to extend the right template (tried looking at accounts\templates\account_form.html but don't think it is there?
I believe if you defined a "choices" arg for the field, it'll do just that:
https://docs.djangoproject.com/en/dev/ref/models/fields/#choices
A quick Google search will probably also reveal some pre-built packages for country lists.

Resources