Is there any chance to add field "Inv. recpt date" to Payment block in Miro tcode so that the user could select "Inv. recpt date" instead of "Baseline Date". Is there any BAdi or BAPI?
There is no direct and straightforward way to add fields to MIRO payment tab, you can only add to details one (check LFDCB001 enhancement).
However you can change payment tab values on-the-fly to whatever you need via MRM_PAYMENT_TERMS BAdI. For changing baseline date in PAYMENT_TERMS_SET method put something like this:
DATA: h_drseg TYPE mmcr_drseg,
h_reindat TYPE RBKP-REINDAT.
LOOP AT ti_drseg INTO h_drseg WHERE selkz = 'X'.
SELECT SINGLE budat FROM ekbe INTO h_reindat WHERE
ebeln = h_drseg-ebeln AND
ebelp = h_drseg-ebelp AND
lfbnr = h_drseg-lfbnr AND
lfgja = h_drseg-lfgja AND
lfpos = h_drseg-lfpos AND
vgabe = '2'.
CHECK sy-subrc = 0.
e_zfbdt = h_reindat.
EXIT.
ENDLOOP.
Here h_reindat is an "Inv. recpt date" which is assigned to baseline date in runtime.
If you want anyway to make it visible in UI for manual entry, I recommend to stick to standard approach described here: How to activate Invoice Receipt Date in document header for any company
It will be put on the MIRO basic tab and then value is copied to baseline date on payment tab.
For your reference: SAP Note 1156325 - BAdIs in the Logistics Invoice Verification environment
Related
I would like to hide a text field based on a date field on an access form. The use will enter a date in the field when they leave, but blank if they are current. I display two dates for years of service (current and after they leave).
Private Sub Form_Current()
If IsNull(DateEnd) Then
Me.YearsOfSeriviceEND.Visible = False
Else
Me.YearsOfSeriviceEND.Visible = True
End If
This does not hide the field, YearsOfSeriviceEND. I'm not sure if this is not working because the field is a date?
Dennis
I've been trying to show order confirmation date in sale order tree view.
To show it I used 'date_order' like this:
<field name="date_order" string="Confirmation Date" optional="show" attrs="{'invisible':[['state','not in',['sale', 'done']]]}" />
In our setup orders are created manually but also synced from Woocommerce and in those synced orders from web shop date_order is always before the create date.
For example order is created (create_date) 10.08.2022 17:10:20 and confirmed automatically (date_order) 10.08.2022 17:10:11
Somehow, it is confirmed 9s before it is created. Now, i'd like to show date_order only when it's value is > create_date. In other cases i'd like to display create_date in it's place.
Tryed to use attrs for this, I'm not sure if it's even possible:
<field name="date_order" string="Confirmation Date" optional="show" attrs="{'invisible':['&', ['state','not in',['sale', 'done']], ['date_order'], '>', ['create_date']]}" />
The code above gives XMLSyntaxError. Not sure if it's possible to compare values in that manner - and finally how to get one or the other value - I guess my second approach is maybe better.
In second approach I tried to create compute field, like this:
date_order_mine = fields.Char("Potvrdjeeeno", compute="comp_date")
#api.depends('create_date', 'date_order', 'order_line')
def comp_date(self):
for order in self:
for line in order.order_line:
if line.create_date < line.date_order:
return line.date_order
else:
return line.create_date
This code gives me AttributeError: 'sale.order.line' object has no attribute 'date_order'
Since I'm so new to Odoo and Python dev I'm not sure what should I do here to compare values of this fields and to return one or other based on conditions - if someone can help I will appreciate it.
The domain used in attrs is not valid, domains should be a list of criteria, each criterion being a triple (either a list or a tuple) of:
(field_name, operator, value)
In your second approach, the date_order field is on the parent model sale.order (order) and to access the date order from order lines , use the order_id field like following:
line.order_id.date_order
To set the value of date_order_mine to create_date or date_order you do not need the order lines and also the computed method should assign the compute value:
Computed Fields
Fields can be computed (instead of read straight from the database) using the compute parameter. It must assign the computed value to the field.
Example:
date_order_mine = fields.Datetime("Potvrdjeeeno", compute="comp_date")
#api.depends('create_date', 'date_order')
def comp_date(self):
for order in self:
if order.create_date < order.date_order:
order.date_order_mine = order.date_order
else:
order.date_order_mine = order.create_date
I have two models a parent and the son contains two float fields
one of the values this calculates according to the other but when I change the father how can be my calculating function.
Here is my example:
class A(models.model):
trv_ids = fields.One2many(classB,id_A)
class B(models.model):
id_A = fields.Many2one(classA)
qtite = fields.float(default=0)
qtite1 = fields.float(default=0,compute=?????)
qtite1 gets the value of qtite when I change parent
as the example of cumulated amount becomes previous quantity the next month.
Thanks
If i understood right i think what you need is something like this:
#api.depends('id_A')
def _compute_qtie1(self):
for record in self:
record.qtite1 = record.qtite
qtite1 = fields.float(compute=_compute_qtie1, store=True)
The depends is what triggers (any time you change the id_A field in the record) the compute method, if you dont store it in the DB it will re-calculate every time you open a view that contains the record.
I am using Odoo v10 .
As we know in purchase.order, there is a base (Monetary) field amount_total which contains value of total amount of a Purchase Order based on (self) currency_id .
Now, I create a new float field home_currency_amount_total in purchase.order .
home_currency_amount_total = fields.Float(string='Total Amount in company currency', store=True)
How can i have a value in this field based on company currency? i.e. I want to have a corresponding value in company base currency and can be used in my tree & form views.
I am new to Odoo and I wonder if there is a "shortcut" (e.g. a built-in compute method) instead of I have to write up related codes.
There is a built-in method for conversion of currency.
Eg.
#api.model
def _compute(self, from_currency, to_currency, from_amount, round=True):
if (to_currency == from_currency):
amount = to_currency.round(from_amount) if round else from_amount
else:
rate = self._get_conversion_rate(from_currency, to_currency)
amount = to_currency.round(from_amount * rate) if round else from_amount * rate
return amount
So, if you want to calculate the conversion you can use this method.
This method takes 3 arguments, first from currency, second to currency and amount which you want to convert as a third argument.
Eg.
self.env['res.currency']._compute(order.currency_id,order.company_id.currency_id,order.amount_total)
Update :
Create you field like this.
home_currency_amount_total = fields.Float(string='Total Amount in company currency', compute="_compute", store=True)
#api.depends('order_lines.price_subtotal','company_id','currency_id')
def _compute(self);
for order in self:
home_currency_amount_total = self.env['res.currency']._compute(order.currency_id,order.company_id.currency_id,order.amount_total)
You can do it using following method.
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
#api.multi
#api.depends('amount_total')
def get_amount_in_company_currency(self):
for purchase_order in self:
if purchase_order.currency_id.id!=purchase_order.company_id.currency_id.id:
currency_id = purchase_order.currency_id.with_context(date=purchase_order.date_order)
purchase_order.home_currency_amount_total = currency_id.compute(purchase_order.amount_total, purchase_order.company_id.currency_id)
else:
purchase_order.home_currency_amount_total=purchase_order.amount_total
home_currency_amount_total = fields.Float(string='Total Amount in company currency',compute="get_amount_in_company_currency",store=True)
In above code we have create one compute field store True, it means value will be store in the database.
When amount_total will change at that time system will calculate home currency amount.
In method we have checked if company currency & purchase order currency is different then system will compute currency amount.
In odoo base module on method is available for compute currency, in which you can pass date in the context.
purchase_order.currency_id.with_context(date=purchase_order.date_order)
Based on context date system will take currency rate, if you not pass
any date then system will take current date rate.
This will help you.
I'm making a module for reservations in Odoo 9 and one field of my model is populated based if it's reserved or no. Basically my model is:
class Reservation(models.Model):
....
room_id = fields.Many2one('reservation.room', string="Room")
I've defined an onchange function that return a domain to filter the room_ids that aren't reserved:
#api.onchange('date')
def _set_available_room(self):
.....
return {'domain': {'room_id': [('id', 'in', res)]}}
This works fine and when I set the date, the rooms are filtered ok. My problem is when I save a reservation and enter again to edit it. The room_id field show all values and only when I change the date the room_id is filtered.
I've tried using the domain attribute in the field definition like this, but it doesn't works:
room_id = fields.Many2one('reservation.room', string="Room", domain=lambda self: self._get_available_slots())
How can I filter this field on the load view using my function than search for available rooms?