Maximo automation script to pull Company Contact's email address - jython

I am trying to pull in the email for a Contact in a specific Company. When a PO buyer creates the PO, they select the Company and the appropriate Contact if it's not the Company's default Contact. The script I created works well in most cases. However, I have Contacts with the same name (i.e. "Customer Service"). When "Customer Service" is selected as the Contact for the Company, the script grabs the first "Customer Service" Contact email it finds, regardless of the Company. This is causing issues for trying to email the vendor the PO details. I would assume I need something to reference the selected Company in the script, but I'm not sure how to do it. Thanks for any answers you can provide!
from psdi.mbo import MboRemote
from psdi.mbo import MboConstants
from psdi.mbo import MboSetRemote
from psdi.mbo import MboSet
from psdi.mbo import Mbo
from psdi.mbo import MboConstants
from psdi.server import MXServer
CONTACT = mbo.getString("CONTACT")
VENDOR = mbo.getString("VENDOR")
CONTACTEMAIL = mbo.getString("CONTACTEMAIL")
if CONTACT!= '':
mbo.setValue("CONTACTEMAIL" , mbo.getString("COMPCONTACT.EMAIL") , MboConstants.NOACCESSCHECK)
else:
mbo.setValue("CONTACTEMAIL" , "" , MboConstants.NOACCESSCHECK)

This can be done more succinctly by creating a crossover domain on PO.CONTACT to populate your custom field on PO (PO.CONTACTEMAIL) with the COMPCONTACT.EMAIL when the PO.contact is populated.
Object: COMPCONTACT Validation
Where Clause: COMPCONTACT.CONTACT = :CONTACT
Crossover Fields:
Source Field: EMAIL
Destination Field: CONTACTEMAIL

Related

Add permission to group (or find where is the problem)

I have this message:
The requested operation can not be completed due to security
restrictions. Document type: Employee (hr.employee) Operation: read
User: 23 Fields: - contract_id (allowed for groups 'Employees /
Officer')
I would not like to add the user to the mentioned group because I want to restrict his actions, and this group has too many permissions. How can I know what permission is required for that specific field?
UPDATE
Create a module with just these lines. I am trying to overwrite the field by deleting the group but it doesn't work for me. What am I doing something wrong?
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo.osv import expression
class Employee(models.Model):
_inherit = "hr.employee"
contract_id = fields.Many2one('hr.contract', string='Current Contract',
domain="[('company_id', '=', company_id)]", help='Current contract of the employee')
Odoo is nice for once and is telling you which field on which model is restricted. So in this case you should look into the field definition and will find:
contract_id = fields.Many2one(
'hr.contract', string='Current Contract',
groups="hr.group_hr_user",
domain="[('company_id', '=', company_id), ('employee_id', '=', id)]",
help='Current contract of the employee')
You can see the groups parameter which will lead to a restriction of this field to the following groups. Here it is one: hr.group_hr_user which is created with the hr App and also mentioned in Odoo's Access Error: "Employees / Officer".
So you could change the field definition, but i don't advise to do that. I'm not sure why there is no possibility for an Employee to atleast see some of the current contract information of his own contract.

Cannot create table in odoo 14

I just created a new module with the following structure:
mainfolder
-models
--__init__.py
`from . import student`
--student.py
```
from odoo import api, fields, models
class SchoolStudent(models.Model):
_name = "school.student"
_description = "School Student Patient"
name = fields.Char(string='Name', required=True)
age = fields.Char(string='Age')
gender = fields.Selection([
('male', 'Male'),
('female', 'Female'),
('other', 'Other'),
], required=True, default='male')
note = fields.Text(string='Description')
```
-__init__.py
`from . import models`
-__manifest__.py
The problem is, when I installed the module, I cannot find the table "School student" in my database, I updated the module several times but the same.
How to fix this issue please?
Thanks
I inform you that I solved the problem just by creating the view and access rights for the module.
Thanks
Odoo15 - For someone who still got this issue:
In my case, i'm missing code in my root __init__.py
My custom module named school and saved inside /var/www/html/odoo_15/addons/school
So the root init file should have path like /var/www/html/odoo_15/addons/school/__init__.py and the content should be
from . import models

Create an invoice from a sales order using XML-RPC (Python)

I'm following the external APIs documentation : https://www.odoo.com/documentation/13.0/webservices/odoo.html
to implement our companies requirements. I'm required to create a sales order and automatically create an invoice after that. The sales order part is done but I cant seem to be able to attach the Invoice to the Sales order
I've tried linking it via the 'invoice_ids' field but the documentation does not mention how to provide a many2many field in it. here is the code:
many2manyInvoice = [(4, invoice_id)]
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
#Admin user Id
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password, 'sale.order', 'write', [[sales_order_id], {'invoice_ids':many2manyInvoice}])
The response returned is 200 , but nothing is happening on the sales order level. I think its the way that I defined the field that might be incorrect.
Can someone help with this issue ? Thanks in advance
Nothing is happening on the sales order level because you are not creating a sales record, writing to it without doing anything. Not sure if this would work in your specific case but here is what I would do.
Use the Pro-forma invoice https://www.odoo.com/documentation/user/13.0/sales/invoicing/proforma.html
Then when a sales record is created run the "Send pro-forma invoice" method using the web api. This takes care of the db linking, as it can get very complicated.

How to get user country without gps

In react native i am trying to get user country without using the users gps, just like Wechat registration which automatically gets the users country in the picker(select) field.
it can be done by two ways
get the IP address of user but it works only with internet connection
the best way is to get the local country of the device itself with the use of
react-native-device-info
const deviceCountry = DeviceInfo.getDeviceCountry(); // "US", "IN"
ref: react-native-device-info#getdevicecountry
getDeviceCountry() is removed from react-native-device-info.
Use react-native-localize:
import * as RNLocalize from "react-native-localize";
RNLocalize.getCountry(); // -> 'UA'
If you want to get a full country name like "United States" then you can add following json file to your project: https://gist.github.com/ssskip/5a94bfcd2835bf1dea52
And then import and get full country name by code:
const countries = require('./countries.json')
// Or in ES6:
// import countries from './countries.json'
countries[RNLocalize.getCountry()] // -> 'United States'

How to show default partner_id in wizard which is selected in sale order form but not saved yet?

I selected the customer name in the sales order form. And above the sale order line, I added a button, for this button wizard is opened and getting information from the customer. I want that in wizard customer name(partner_id) should be auto-filled when the user opens it. So, how can I do that?
Wizard file code is:
class RentalPackWizard(models.TransientModel):
_name = "rental.pack.wizard"
_description = "Rental Pack Wizard"
"""#api.model
def _get_default_partner(self):
partner = self.env['res.partner'].search([()], limit=1)
return partner"""
ser6_partner_id = fields.Many2one('res.partner', string='Customer')# , default=_get_default_partner)
Also Attached image for problem
In your xml use context to pass values.
Example:
context="{'default_partner_id':partner_id}"